Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp echoing array from php function
    primarykey
    data
    text
    <p>Alright I am still learning my functions in php but this particular piece of code has me stuck. Credit goes to <a href="http://www.barattalo.it/2010/08/29/php-bot-to-get-wikipedia-definitions/" rel="nofollow">http://www.barattalo.it/2010/08/29/php-bot-to-get-wikipedia-definitions/</a> for the wikipedia query segment. I thought this looked interesting and am trying to use the code provided to echo data from the function. This is what I have:</p> <pre><code>&lt;?php function wikidefinition($s) { $url = "http://wikipedia.org/w/api.php?action=opensearch&amp;search=".urlencode($s)."&amp;format=xml&amp;limit=1"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPGET, TRUE); curl_setopt($ch, CURLOPT_POST, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_NOBODY, FALSE); curl_setopt($ch, CURLOPT_VERBOSE, FALSE); curl_setopt($ch, CURLOPT_REFERER, ""); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_MAXREDIRS, 4); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"); $page = curl_exec($ch); $xml = simplexml_load_string($page); if((string)$xml-&gt;Section-&gt;Item-&gt;Description) { return array((string)$xml-&gt;Section-&gt;Item-&gt;Text, (string)$xml-&gt;Section-&gt;Item-&gt;Description, (string)$xml-&gt;Section-&gt;Item-&gt;Url); } else { return "blank"; } } $define = wikidefinition("test"); echo $define; ?&gt; </code></pre> <p>however this simply echos "array" I know the code is getting to the if/else statement because if you change the input in "$define = wikidefinition("test");" to some random key combination such as "qoigenqnge" it will echo "blank" I cannot figure out why it is only echoing "array" instead of the data inside the array. Probably something stupid, but I have been reading up on arrays for a while and cant find any info. Any help will be great thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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