Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to filter JSON and XML. PHP
    text
    copied!<p>I have a function that gets friends and followers of a twitter account. I'm making a "Who's Not Following back app" How do I filter the xml/json data (I can use both) ie to echo what is in following but not in followers.</p> <p>Here's my code</p> <pre><code>function twitter_notf_page($query) { $user = $query[1]; if (!$user) { user_ensure_authenticated(); $user = user_current_username(); } $request = API_URL."statuses/friends/{$user}.xml"; $tla = lists_paginatedd_process($request); $request = API_URL."statuses/followers/{$user}.xml"; $tl = lists_paginatedd_process($request); $content = "&lt;h2&gt;FRIENDS&lt;/h2&gt;"; $content .= theme('notf', $tla); $content.="&lt;br&gt;&lt;hr&gt;"; $content .= "&lt;h2&gt;FOLLOWERS&lt;/h2&gt;"; $content .= theme('notf', $tl); theme('page', 'Followers', $content); } function lists_paginatedd_process($url) { // Adds cursor/pagination parameters to a query $cursor = $_GET['cursor']; if (!is_numeric($cursor)) { $cursor = -1; } $url .= '?cursor='.$cursor; $xml = twitter_process($url); $ret = simplexml_load_string($xml) return $ret; } </code></pre> <p>Results - Following</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;users_list&gt; &lt;users type="array"&gt; &lt;user&gt; &lt;id&gt;66968592&lt;/id&gt; &lt;name&gt;DJ Swaggz &amp;#11013;click2fol&lt;/name&gt; &lt;screen_name&gt;DjSwaggz&lt;/screen_name&gt; &lt;/user&gt; &lt;user&gt; &lt;id&gt;288859268&lt;/id&gt; &lt;name&gt;tegan shanks&lt;/name&gt; &lt;screen_name&gt;teganxroshanks&lt;/screen_name&gt; &lt;/user&gt;&lt;/users_list&gt; </code></pre> <p>Results - Followers</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;users_list&gt; &lt;users type="array"&gt; &lt;user&gt; &lt;id&gt;66968592&lt;/id&gt; &lt;name&gt;DJ Swaggz &amp;#11013;click2fol&lt;/name&gt; &lt;screen_name&gt;DjSwaggz&lt;/screen_name&gt; &lt;/user&gt; &lt;/user&gt;&lt;/users_list&gt; </code></pre> <p>I want this guy to display (The one that's not following back)</p> <pre><code> &lt;user&gt; &lt;id&gt;288859268&lt;/id&gt; &lt;name&gt;tegan shanks&lt;/name&gt; &lt;screen_name&gt;teganxroshanks&lt;/screen_name&gt; &lt;/user&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload