Jump to content

Recommended Posts

Hello

(Please refer codes below)

I want to have only "ids" field fetched in some variable under foreach() [in bold font] 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 in bold - same loop mentioned above).

$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) :

if ($step=='send_invites')

{

if ($inviter->showContacts())

{

$contents.="<table class='thTable' align='center' cellspacing='0' cellpadding='0'><tr class='thTableHeader'><td colspan='".($plugType=='email'? "3":"2")."'>Your contacts</td></tr>";

if (count($contacts)==0)

$contents.="<tr class='thTableOddRow'><td align='center' style='padding:20px;' colspan='".($plugType=='email'? "3":"2")."'>You do not have any contacts in your address book.</td></tr>";

else

{

$contents.="<tr class='thTableDesc'><td><input type='checkbox' onChange='toggleAll(this)' name='toggle_all' title='Select/Deselect all' checked>Invite?</td><td>Name</td>".($plugType == 'email' ?"<td>E-mail</td>":"")."</tr>";

$odd=true;$counter=0;

foreach ($contacts as $email=>$name)

{

$counter++;

if ($odd) $class='thTableOddRow'; else $class='thTableEvenRow';

$contents.="<tr class='{$class}'><td><input name='check_{$counter}' value='{$counter}' type='checkbox' class='thCheckbox' checked><input type='hidden' name='email_{$counter}' value='{$email}'><input type='hidden' name='name_{$counter}' value='{$name}'></td><td>{$name}</td>".($plugType == 'email' ?"<td>{$email}</td>":"")."</tr>";

$odd=!$odd;

}

 

facebook.php code (getMyContacts() function) :

public function getMyContacts()
{
if (!$this->login_ok)
{
$this->debugRequest();
$this->stopPlugin();
return false;
}
else $url=$this->login_ok;
$res=$this->get($url,true);
if ($this->checkResponse("get_friends",$res))
$this->updateDebugBuffer('get_friends',"{$url}",'GET');
else
{
$this->updateDebugBuffer('get_friends',"{$url}",'GET',false);
$this->debugRequest();
$this->stopPlugin();
return false;
}

$nextPage=true;$page=0;$contacts=array();
while($nextPage)
{
$nextPage=false;
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;	
}
else return $contacts;
}
else return $contacts;
}
else return $contacts;
if (!empty($nextPage)) $res=$this->get($nextPage,true);
$page++; 
}
return $contacts;
}

 

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.

 

I'm attaching full files if you need them.

In short, all i wanna do is -

Under foreach() loop (in bold font) in example.php, i can access $email and $name

and $email contains values is this fashion :  /inbox/?rfbafefaa&r3b54c457&compose&ids=1234567890&refid=5

I wanna have those numbers in "ids="  in some string variable (for comparison purpose etc. I'm not gunna echo ids data anywhere... it will b used internally for comparison etc.)

Please check attached files for full code..

(If you download zip, please look in to

../help/example.php

../help/includes/facebook.php

 

The other files are attached just in case needed.)

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/176354-php-parse_str-help-needed-low-priority/
Share on other sites

I'm sorry.. I think I speak for most people whose viewed this post when I say this topic is EXTREMELY long, and its awefully late here,

 

but I'm going to attempt to help.. lol.. could you show us a print_r of $emails before the foreach loop.

Here is print_r($contacts) 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 )

 

Thanks a million for taking your time man... please tell me how do i solve this???

Its driving me crazy sine past 48 hours... i skipped work for past 2 days and today also i'm gunna skip again... its just driving me nuts!!!!  :confused:

lolz... cooking is my hobby!!! i love watching cooking channels over news or any dumb movies stuff... lolz!!

 

btw that didnt worked...

 

I guess it will get solved if we separate ids in getmycontacts() function only... the place where "return $contacts" is written.

If we parse_str($href) or parse_str($hrefs) in that function and add it to the array as 3rd index.

I guess it will get solved.

But i dont know exact syntax of how to write that..

 

Sorry, I know this isn't what you are looking for, but it is extremely difficult to read your code.  Tabs (or spaces) are your friends.  Make your code easier to read, and it will be easier for you and us to debug.

 

This:

 

if ($odd) $class='thTableOddRow'; else $class='thTableEvenRow';

 

Is also the perfect example of where to use the ternary operator.  I know what I say could be controversial, but in my opinion, being able to quickly and easily address the issue at hand is important, consider instead:

 

$class = ($odd) ? "thTableOddRow" : "thTableEvenRow";

 

Or, one of my favorites:

 

$class = (++$toggler %2 == 0) ? "even" : "odd";

 

Sorry for not addressing the question, I'm just trying to help in general and don't want to wade through that (but seriously, tabs, or spaces, can make your code tell a story rather than on-screen vomit)!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.