PHP - File Get Contacts Between Strings
Good day all.
I am trying to get strings from txt file with a start and an end.
$file = "/var/www/html/sataxicrm/custom/include/language/lang.en_us.lists.php"; $content = file_get_contents($file); $pos = strpos($content,"query_complaint_type_list"); $end = strpos($content,"status_0"); $string = substr($content,$pos,($end- $pos)); $array = nl2br($string); //print $content; echo "Database Value:Label Value <br>"; print $array;
The above code works well if you knowwhat your end string is, but in my case i do not know. i only know the start. As you can see i know it starts with account_type_dom but i do not know that it will end before industry_dom. so i need to stop before industry_dom. how do i do this? Quote
account_type_dom
Similar TutorialsHi! What i can't figure out, is how to delete between 2 given strings in another file. Explanation: I have a file, it contains following: Code: [Select] ### Start of content 0 ### Some Radom Lines with text 1 ### End of content 0 ### ### Start of content 1 ### Some Radom Lines with text 2 ### End of content 1 ### ### Start of content 2 ### Some Radom Lines with text 3 ### End of content 2 ### And so on, now i need code, which can find line i give and delete between. Something like this: If, i give string: Code: [Select] ### Start of content 0 ### Then it will delete this line to the Code: [Select] ### End of content 0 ### Hope you can help! All the best: Mart L. Hello I am after some help with a concept to allow us to import some data into our database. I have a PDF which I have OCR'd and now have a word document... I then manually clean up the document to remove spurious characters, that part is fine. Now, the word document contains an unknown number of lines and an unknown number of records... and within those records an uknown number of fields... Here is an example of a single record: Mr G Aldred, 26/11/08, Canvardine Chance, Wolfies Dawn Tilley, KENINE SECRET DESTINY, d, c. Grey & White, KENINE SHADES OF THE NIGHT, d, c. Grey & White, KENINE SILENT WHISPER, b, c. Seal & White, KENINE SOFT KISSES, b, c. Grey & White, KENINE SPIRIT OF THE STORM, d, c. Seal & White KENINE STAR QUALITY, d, c. Seal & White And I could have multiple records like this, but with different number of names toward the end So, if I manually put some delimiting character instead of coma's , can I get PHP to read the WHOLE document in, split the document into records and then split those records into subfields to populate a form which I can then automatically submit to my database? Not sure if that is clear.... Thanks I am writing a google contact API to get users contacts, I get everything back except for the email address of the contact. Anyone know how to get the contacts email address? Code: [Select] <?php class gdata{ private $headers; private $googleAuth = 'http://www.google.com/mate/feeds'; private $google = 'http://www.google.com/mate/feeds/contacts/default/full'; public $token; public function headers(){ $this->headers['GData-Version'] = '3.0'; $this->headers['Authorization'] = "AuthSub token=\"$this->token\""; $this->headers['Content-Type'] = "application/x-www-form-urlencoded"; $this->headers['Host'] = "www.google.com"; $this->headers['User-Agent'] = "php/".phpversion(); $this->headers['Accept'] = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"; $this->headers['Connection'] = "keep-alive"; } public function request_contacts($email){ $ch = curl_init(); $headers = array(); foreach($this->headers as $k => $v){ $headers[] = "$k: $v"; } $url = preg_replace("/\[email_address\]/", $email, $this->google); echo $url; curl_setopt($ch, CURLOPT_URL, $this->google); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $opt = curl_exec($ch); $xml = simplexml_load_string($opt); header("Content-type: text/plain"); foreach($xml->entry as $user){ //echo $user['link'] } print_r($xml->entry[5]); } public function auth(){ $next = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?a=getContacts'; header("Location: https://www.google.com/accounts/AuthSubRequest?next=".urlencode($next)."&scope=".urlencode($this->googleAuth)."&session=1&secure=0"); } } $gAPI = new gdata(); if($_GET['a'] == 'getContacts'){ $gAPI->token = $_GET['token']; $gAPI->headers(); $gAPI->request_contacts('untuned20@gmail.com'); }else{ $gAPI->auth(); } ?> Good morning I am trying to add an "add to contacts" button to the user profile page that is viewed by other users but I seem to be struggling to wrap my head around this one. I can create the search user page that populates a list of users based on search criteria and link to their respective profiles using GET. But now if I have a "add to contacts" button on their profile page, I am struggling with the code to insert this into a contacts table correctly. If the contacts table has a id column, user_id column and contacts_id column how do I insert the id of the user you are viewing into the contacts_id column? I should have something along these lines....: Code: [Select] if (isset($_SESSION['user_id'])) $user_id = ($_POST['user_id']); $sql_insert = "INSERT into `contacts` (`user_id`,`id`,`date`) VALUES ('".$_SESSION['user_id']."','$id',now())"; mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error()); $user_id = mysql_insert_id($link); but that is not going to add the id as contact id for the profile being viewed. Should this be done totally differently? Any help in this regard would be highly appreciated. Apologies if I have not explained properly. Thank you I need to write a code were users can login to his/her email account from my site to import contacts to be selected and used. I know you need to use api's for this. Has anyone done this before who can give me some useful tips? How can I recover deleted iphone contacts?
I have a PHP application and am trying to allow users to import contacts from their favorite email systems. Right now, I'm targeting yahoo, gmail and hotmail - facebook friends would also be interesting. I'll need to allow users to log in, of course, and then have all of their contacts pulled into my application. From there, I'll present them to the user and allow them to pick which ones they want to email about my application. The important part is that I need to have control over what happens to the contact list to control certain aspects of my application. So, here are my questions: > Is CURL the right method to use to do this? > Are there practical examples available that I can use and where might I find them? > What things would I need to be aware of and prepare for regarding security/hacking since I'm accessing remote sites? Thanks for your guidance. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321126.0 Not sure if there is a better way to do this, but I want to check whether the value in a Sticky Field is the same as what is in the Database. If what is in the Sticky Field is *exactly* what is in the Database, then the User didn't update that field, and so I would NOT do an UPDATE. Seem reasonable? Here is where I grab the value out of the Form... Code: [Select] // **************************** // Process Each Form Field. * // **************************** foreach($_POST['answerArray'] as $questionID => $response){ // Copy trimmed Form array to PHP array. $answerArray[$questionID] = trim($response); And here is where I grab the existing value in the Database... Code: [Select] // ******************** // Check for Answer. * // ******************** // Build query. $q1 = "SELECT response FROM bio_answer WHERE member_id=? AND question_id=?"; // Prepare statement. $stmt1 = mysqli_prepare($dbc, $q1); // Bind variable to query. mysqli_stmt_bind_param($stmt1, 'ii', $memberID, $questionID); // Execute query. mysqli_stmt_execute($stmt1); // Store results. mysqli_stmt_store_result($stmt1); // Check # of Records Returned. if (mysqli_stmt_num_rows($stmt1)==1){ // Answer Found. // Bind result-set to variable. mysqli_stmt_bind_result($stmt1, $currResponse); // Fetch record. mysqli_stmt_fetch($stmt1); So I guess I want to compare $answerArray[$questionID] against $currResponse and see if there are any differences?! What is the best way to do that? Any better ideas of how to check to see if the User made any changes to a field so I only do an UPDATE if there was actually a change? Thanks, Debbie hello, here is what i have, obviosly it doesnt work. Code: [Select] $year=$_POST['y']; $yr=substr($year,-2); $mth=$_POST['m']; $init=$_POST['initial']; $jobnumber=$yr$mth2343$init; echo "$jobnumber"; P.S. thanks to everybody for their help lately! Hey guys!! So basically what I am doing here is pulling the directory out of a url. URL ex: http://www.xxx.com/T...IS_WHAT_I_WANT/ How can i break down strings for example i have a simple search database for products where as a user searches a term this can be one, two three words and so on. I'm using a wildcard; but i want the best way to get the possible search so i would like to break down the string into separate words and then use that to search the database using wildcards is this possible? Thanks for reading. I was thinking how can I make a script that will build strings incrementing through each letter starting with "a" and ending with "zzzzzz" or what ever ending length I want such as 12. So if your were to output everything, you could find the words: "dog" "spider" "superman" "hippo" etc What would be the best way to do this, so I don't have to have a loop that is 500 blocks deep to show a word that is 500 letters example Quote a ... z aa ab ac ... az ba bb bc ... ... aaa aab aac Hi I am having troubles using a string in a cookie.. This doesnt work: setcookie("background", "$image_name", $expire, "/", ".gedoo.com"); Neither does this: setcookie("background", "" . $image_name . "", $expire, "/", ".gedoo.com"); If I write something before $image_name like: setcookie("background", "hello" . $image_name . "", $expire, "/", ".gedoo.com"); It will save "hello" in the cookie.. So in other words, $image_name doesnt look like it is defined.. But the funny thing is that this works on the same page: echo "File Uploaded Successfully!<br><img src='images/$image_name'>"; Anyone have any idea on what I am doing wrong? Hello, I was wondering if someone could help me to "get" the webaddress of a current webpage and then pull off pieces of the page. All of my pages look like: http://localhost:8888/algebra_book/Chapters/Quadratic_Functions/introductory_problem.php BUT, the stuff to the left of Quadratic Functions WILL change in the future. So all will look like: *Quadratic_Functions/introductory_problem.php Then, I'd like to pull off a $chapter variable, which in this case is Quadratic_Functions and a $page_name variable which in this case will be introductory_problem. Thanks so much. is there a way I can make something like a ticket in pdf format that can have $name or the likes echo in it? if you could help get me started, that would be great! Let's say I have the string "Bob is my friend. Bob likes to eat apples. Goodbye!". I give a function that string, and the two strings "Bob" and "apples". It returns "Bob likes to eat apples". I seem to have trouble making this function. If I wanted it to return "Bob is my friend. Bob likes to eat apples" that would be much simpler, but I am trying to get the smallest amount of characters between the two strings. I tried doing this, but seem to either get stuck on an infinite loop or return the entire inputted string. Code: [Select] function between($strIn, $str1, $str2){ $pos2 = stripos($strIn, $str2); $pos = 1; $strStore = ""; while($pos>0 && $pos<$pos2){ $pos = stripos($strIn, $str1); $strStore = substr($strin, $pos, $pos2-$pos); $strIn = substr_replace($srtIn, $strtemp, ""); } return $strStore; } What it does it finds the first occurrence of "apples" ($str1) and then keeps finding and deleting every occurrence of "Bob" ($str2) until the position of "Bob" surpasses the position of "apples". As you can tell, it doesn't work. Could anyone help me out, or tell me what I am doing wrong? Hey Im trying to extract urls from inputted data so i can seperate it from the rest of the text but can't seem to work out what regex i need to use. The main issue is im trying to extract a specific domain example (google.com) But it could be written 4 ways (google.com, http://google.com, http://www.google.com, www.google.com). Does any one know how you do it ? Hello guys, need some help. Let us say i have an array = 2011 ipad 2011 ipad review 2011 ipad price 2011 ipad design 2011 ipad reviews review 2011 ipad 2011 ipad feature I would like to review all the array elements that contain "review"...So the final array should look like 2011 ipad 2011 ipad price 2011 ipad design 2011 ipad feature Thanks |