Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Read XML ouput 1

Status
Not open for further replies.

sen5241b

IS-IT--Management
Sep 27, 2007
199
US
I'm using curl with the following URL in the shell_exec command to get some HTML and XML output into a PHP variable:

Code:
[URL unfurl="true"]http://en.wikipedia.org/w/api.php?action=query&prop=info&titles=hjflksjhdfuibv[/URL]

If I put that URL into a firefox webpage it outputs this:

Code:
You are looking at the HTML representation of the XML format.
HTML is good for debugging, but probably is not suitable for your application.
See complete documentation, or API help for more information. 
<?xml version="1.0"?>
<api>
  <query>
    <normalized>
      <n from="hjflksjhdfuibv" to="Hjflksjhdfuibv" />
    </normalized>
    <pages>
      <page ns="0" title="Hjflksjhdfuibv" missing="" />
    </pages>
  </query>
</api>

A var_dump of the PHP var, however, does not have all the XML shown above --most of it is just not there. I need to get all of the XML shown above into a PHP var and read it raw without regard to the fact that its XML.

BTW, my overall purpose is simply to determine if a topic exists in Wikipedia.
 
This code lets me determine if a topic exists on Wikipedia. It uses a line mode webpage reader called curl.exe.

Code:
function WikipediaLookup($word)
{
$curl_program	= 'curl';		// curl used for wikipedia lookup. Do not put '.exe' on end.
echo '<br> wiki begin!';

$WikipediaLink = '"[URL unfurl="true"]http://en.wikipedia.org/w/api.php?action=query&titles=';[/URL]
$article = $word;
$Doubquote = '"';
$format = '&format=txt';
$curlcommand = $curl_program . ' ' . $WikipediaLink . $article . $format . $Doubquote;
echo '<br> in wiki lookup $curlcommand=' . $curlcommand;
$Wikioutput = shell_exec($curlcommand);
echo '<br> after $Wikioutput=';
var_dump($Wikioutput);
$pos = strpos($Wikioutput, '[missing]');
if ($pos === false) 
	{
   echo '<br>The wikipedia lookup found the topic ' . $word;
	return true;;
	} 
	else 
	{ 
    echo '<br>The wikipedia lookup found no topic ' . $word;
	return false;
	}
}
 
That is much better and probably safer than having an EXE on the server. thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top