I want to get the IMG SRC tag from the following code:
<pod title="Scientific name" scanner="Data" id="ScientificName:SpeciesData" position="200" error="false" numsubpods="1">
<subpod title="">
<plaintext>Canis lupus familiaris</plaintext>
<img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17941cd1c5fi21h72ac2000057i1ae7gc4986gdf?MSPStoreType=image/gif&s=44" alt="Canis lupus familiaris" title="Canis lupus familiaris" width="139" height="18"/>
</subpod>
</pod>
I know how to get the plaintext information but how do I get the img src information? Here's what I have to get the plaintext information:
<?php
if(isset($_POST['q'])){
include 'WolframAlphaEngine.php';
$engine = new WolframAlphaEngine( 'APP-ID' );
$resp = $engine->getResults("$q");
$pod = $resp->getPods();
$pod1 = $pod[1];
foreach($pod1->getSubpods() as $subpod){
if($subpod->plaintext){
$plaintext = $subpod->plaintext;
break;
}
}
$result = substr($plaintext, 0,strlen($plaintext)-3);
echo "$plaintext";
}
?>
It's not a duplicate of Grabbing the href attribute of an A element because I can't use DOM on my Godaddy hosting. I've tried it before.
I've never worked with that WolframAlphaEngine before. I assume it's this one:
If so, have a look at https://github.com/brkeerthi/chethana/blob/master/include/WASubpod.php
class WASubpod {
// define the sections of a response
public $attributes = array();
public $plaintext = '';
public $image = '';
public $minput = '';
public $moutput = '';
public $mathml = '';
As you can see, it has properties not only for plaintext, but also for attributes and other stuff. It might be as easy as
foreach ($pod1->getSubpods() as $subpod) {
$attributes = $subpod->attributes;
if (isset($attributes['src']) {
echo $attributes['src'];
}
}
But since the documentation of that library is non-existent, I cannot tell. So if this doesn't work, just var_dump
the $subpod
to see what it contains.
Likewise, have a look at the other classes to find out what they do: