Hello (Please refer codes below) I want to have only "ids" field fetched in some variable under foreach() [Line 184] loop in example.php Currently, facebook.php contains following string in $email field after successful execution. I echoed $email in show contacts step (under foreach loop on line 184). $email contains : /inbox/?rfbafefaa&r3b54c457&compose&ids=1234567890&refid=5 i wanna have only $ids numbers in 1 string variable. example.php code (code block where i want ids in some variable) : facebook.php code (getMyContacts() function) : So here is what i've tried so far : in example.php, ---------------------------------------------------------------------- after : foreach ($contacts as $email=>$name) { $counter++; I wrote : foreach ($contacts as $email=>$name) { $counter++; parse_str($email,$tempxx); $idsxx=$tempxx['ids']; --------------------------------------------------------------------- The above code results no data in variable $idsxx. I also tried following in foreach lop above : ------------------------------------------------ foreach ($contacts as $email=>$name) { $counter++; parse_str($email); $idsxx=$ids; ------------------------------------------------- Above code also results no data in variable $idsxx I tried following in same foreach() loop : ------------------------------------------------- foreach ($contacts as $email=>$name) { $counter++; if (preg_match('/ids=([0-9]+)/', $email, $match)) { $idsxx=$match[1]; } --------------------------------------------------- Above code also results no data in variable $idsxx Can somebody please tell me how do i get ids from $email? Another thing, i also tried to figure out how do i pass ids in $contacts array (in facebook.php) but i couldn't. There i tried to parse_str() $href and $hrefs and also $res. But no luck. Please some one help me. You will get full credits for solving this issue.
As an example I tried this code: $u = "/inbox/?rfbafefaa&r3b54c457&compose&ids=1234567890&refid=5"; parse_str($u,$a); print_r($a); PHP: and got Array ( [/inbox/?rfbafefaa] => [r3b54c457] => [compose] => [ids] => 1234567890 [refid] => 5 ) Code (markup): Try this example too and if failed - that should be some hosting troubles. PHP version or something about it. Acording to getmyContacts() this should work: foreach ($contacts as $email=>$name) { $counter++; parse_str($email,$tempxx); $idsxx=$tempxx['ids']; } PHP: It the first example works fine and you still have no result I suggest print_r($contacts) on each step cause </td>".($plugType == 'email' ?"<td>{$email}</td>":"")."</tr>"; PHP: according to this code $email should contain an email and not something like "/inbox/?rfbafefaa&r3b54c457&compose&ids=1234567890&refid=5" I suppose $contacts array is altered somewhere after getMyContacts()
Thank you very much AshinE but that didnt worked. I did referred to parse_str() manual on php.. and tried all examples.. also i googled a lot.. the reason i posted here because only some1 with experience can solve this. However, i dont understand print_r($contacts)? foreach loop is : foreach ($contacts as $email=>$name) And yeah $email dosnt contain email... facebook display emails as image. So i would have to write OCR routine to fetch that. So $email contains inbox link. Anyway, how do i get that ids parameter?
It is really strange. Then try this one: if (preg_match('/ids=(\d+)/s', $email, $regs)) { $ids = $regs[1]; } else { $ids = ""; } PHP: I have one idea why parse_str() does not work, look: $nextPage='http://m.facebook.com'.str_replace('&','&',$next[1]); PHP: It seems like & are encoded as & in page so $email could be something like that: $u = "/inbox/?rfbafefaa&r3b54c457&compose&ids=1234567890&refid=5"; PHP: but this will still display as normal & in browser. P.S. I dont have a facebook account, so I can't check it.
But still following code should have done the trick : foreach ($contacts as $email=>$name) { $counter++; parse_str($email); $idsxx=$ids; PHP: Now about what you said, Exactly but where to add it and how to access it... foreach ($contacts as $email=>$name) { $counter++; parse_str($email); $idsxx=$ids;[/code] [code]if (preg_match('/ids=(\d+)/s', $email, $regs)) { $ids = $regs[1]; } else { $ids = ""; }[/code] Exactly... but where do i suppose to add that? Please see below code part from getmycontacts() function : [code]if (preg_match_all("#\<td\>\<a href\=\"\/profile\.php(.+)\>(.+)\<\/a\>#U",$res,$names)) if (!empty($names[2])) if (preg_match_all("#\<small\>\<a href\=\"\/inbox\/(.+)\"\>#U",$res,$hrefs)) foreach($hrefs[1] as $key=>$href) if (!empty($names[2][$key])) $contacts["/inbox".$href]=htmlspecialchars($names[2][$key]); if (preg_match_all("#\<div class\=\"pager\"\>(.+)\<\/div\>#U",$res,$pagerBulk)) { if (!empty($pagerBulk[1][1])) { $temps=explode(' ',$pagerBulk[1][1]); $key=count($temps)-2; if (!empty($temps[$key])) { if (preg_match("#\<a href\=\"(.+)\"\>#U",$temps[$key],$next)) $nextPage='http://m.facebook.com'.str_replace('&','&',$next[1]); else return $contacts; PHP: I dont understand how and what is coded there... but under foreach() loop, i can directly access data with $name and $email. So is it possible that we can add 1 preg_match() in above getmycontacts() code to have ids somewhere and then access 'em under foreach() as $ids or something like that.... so i cant understand where i'm suppose to do that and how..
Yes, it should but I do have this output: Array ( [/inbox/?rfbafefaa] => [amp;r3b54c457] => [amp;compose] => [amp;ids] => 1234567890 [amp;refid] => 5 ) Code (markup): Array key of array is not "ids" - it is "amp;ids"
Already tried all that but that aint working... I wrote print_r($contacts) just before foreach() loop in example.php Following is the output : Array ( [/inbox?rc89419ad&r25b4c932&compose&ids=645976873&refid=5] => Aditya Hajare [/inbox?r5aab8b97&r82f9007d&compose&ids=713878257&refid=5] => Kartik Iyer [/inbox?r9fb90a53&rddc4cc0d&compose&ids=714935023&refid=5] => Keyur Girish Godse [/inbox?r6425e4a9&re24d1756&compose&ids=100000273909058&refid=5] => Kiran Kamble ) Code (markup):
I don't even know what to say: <? $contacts = array( "/inbox?rc89419ad&r25b4c932&compose&ids=645976873&refid=5" => "Aditya Hajare ", "/inbox?r5aab8b97&r82f9007d&compose&ids=713878257&refid=5" => "Kartik Iyer ", "/inbox?r9fb90a53&rddc4cc0d&compose&ids=714935023&refid=5" => "Keyur Girish Godse ", "/inbox?r6425e4a9&re24d1756&compose&ids=100000273909058&refid=5" => "Kiran Kamble " ); foreach ($contacts as $email=>$name) { $counter++; if (preg_match('/ids=(\d+)/s', $email, $regs)) { $idsxx = $regs[1]; } else { $idsxx = ""; } echo $idsxx; echo "\r\n"; } PHP: outputs 645976873 713878257 714935023 100000273909058 Code (markup):
Yeah thats what output is expected... and i dont wanna echo $idsxx. I tried same code above... preg_match() pattern in foreach() loop... and $idsxx doesnt contain anything... its blank.. its not getting those numbers.