Note that there are some explanatory texts on larger screens.

plurals
  1. POGet IMG SRC info to show image
    primarykey
    data
    text
    <p>I have the following code that gets some information from the wolframalpha api:</p> <pre><code>&lt;?php if(isset($_POST['q'])){ include 'WolframAlphaEngine.php'; $engine = new WolframAlphaEngine( '9QA6R9-VGL4AAURHU' ); $resp = $engine-&gt;getResults("$q"); $pod = $resp-&gt;getPods(); $pod1 = $pod[1]; foreach($pod1-&gt;getSubpods() as $subpod){ if($subpod-&gt;img){ $plaintext = $subpod-&gt;img; break; } } $pod2 = $pod[2]; foreach($pod2-&gt;getSubpods() as $subpod2){ if($subpod2-&gt;plaintext){ $plaintext2 = $subpod2-&gt;plaintext; break; } } $result = substr($plaintext, 0,strlen($plaintext)-3); preg_match( '|img src="([^"]+)"|', $plaintext, $matches ); $img_src = $matches[1]; echo "$img_src&lt;br&gt;&lt;img src='$img_src'&gt;"; echo "&lt;br&gt;&lt;br&gt;"; echo $plaintext2; } ?&gt; </code></pre> <p>There's a img tag within each subpod. How do I get the img src and display the image?</p> <p>I know it's within here:</p> <pre><code>foreach($pod1-&gt;getSubpods() as $subpod){ if($subpod-&gt;img){ $plaintext = $subpod-&gt;img; break; } } </code></pre> <p><br><br> Here is the context:</p> <pre><code>&lt;queryresult success="true" error="false" numpods="10" datatypes="Species" timedout="" timedoutpods="" timing="2.944" parsetiming="0.076" parsetimedout="false" recalculate="" id="MSPa17911cd1c5fi21h72ac20000332e54b60gcg1bff" host="http://www4a.wolframalpha.com" server="44" related="http://www4a.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa17921cd1c5fi21h72ac20000535d27652696856c&amp;s=44" version="2.6"&gt; &lt;pod title="Input interpretation" scanner="Identity" id="Input" position="100" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt;dog (animal)&lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17931cd1c5fi21h72ac2000021h88ec64ehf1h10?MSPStoreType=image/gif&amp;s=44" alt="dog (animal)" title="dog (animal)" width="89" height="18"/&gt; &lt;/subpod&gt; &lt;/pod&gt; &lt;pod title="Scientific name" scanner="Data" id="ScientificName:SpeciesData" position="200" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt;Canis lupus familiaris&lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17941cd1c5fi21h72ac2000057i1ae7gc4986gdf?MSPStoreType=image/gif&amp;s=44" alt="Canis lupus familiaris" title="Canis lupus familiaris" width="139" height="18"/&gt; &lt;/subpod&gt; &lt;/pod&gt; &lt;pod title="Alternate scientific names" scanner="Data" id="AlternateScientificNames:SpeciesData" position="300" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt;Canis familiaris | Canis familiaris domesticus&lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17951cd1c5fi21h72ac200004345f656d2010iea?MSPStoreType=image/gif&amp;s=44" alt="Canis familiaris | Canis familiaris domesticus" title="Canis familiaris | Canis familiaris domesticus" width="301" height="18"/&gt; &lt;/subpod&gt; &lt;/pod&gt; &lt;pod title="Taxonomy" scanner="Data" id="Taxonomy:SpeciesData" position="400" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt; kingdom | Animalia (animals) phylum | Chordata (chordates) class | Mammalia (mammals) order | Carnivora (carnivores) family | Canidae (coyotes, dogs, foxes, jackals, wolves...) genus | Canis species | Canis lupus (gray wolf) &lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17961cd1c5fi21h72ac200003ec116f8g9gh4274?MSPStoreType=image/gif&amp;s=44" alt="kingdom | Animalia (animals) phylum | Chordata (chordates) class | Mammalia (mammals) order | Carnivora (carnivores) family | Canidae (coyotes, dogs, foxes, jackals, wolves...) genus | Canis species | Canis lupus (gray wolf)" title="kingdom | Animalia (animals) phylum | Chordata (chordates) class | Mammalia (mammals) order | Carnivora (carnivores) family | Canidae (coyotes, dogs, foxes, jackals, wolves...) genus | Canis species | Canis lupus (gray wolf)" width="424" height="228"/&gt; &lt;/subpod&gt; &lt;states count="1"&gt; &lt;state name="More" input="Taxonomy:SpeciesData__More"/&gt; &lt;/states&gt; &lt;/pod&gt; &lt;pod title="Biological properties" scanner="Species" id="SpeciesDataPhysicalProperties" position="500" error="false" numsubpods="4"&gt; &lt;subpod title="Basic properties"&gt; &lt;plaintext&gt;lifespan | (15 to 20) years&lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17971cd1c5fi21h72ac2000067054fficad60e67?MSPStoreType=image/gif&amp;s=44" alt="lifespan | (15 to 20) years" title="lifespan | (15 to 20) years" width="205" height="36"/&gt; &lt;/subpod&gt; &lt;subpod title="Sensory organs"&gt; &lt;plaintext&gt; eyeball diameter | 0.83 inches (human: 0.94 in) eyeball volume | 0.31 in^3 (cubic inches) (human: 0.4 in^3) visual field | 250° (degrees) eardrum surface area | 46 mm^2 (square millimeters) (human: 55 mm^2) angle of auditory acuity | 2.5° (degrees) (human: 8.4°) upper limit of hearing ability | 140 kHz (kilohertz) (human: 21 kHz) olfactory epithelium receptor count | 2.3×10^8 (human: 3×10^7) olfactory epithelium surface area | 13 in^2 (square inches) (human: 0.39 to 0.78 in^2) &lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17981cd1c5fi21h72ac2000053f883b59b99g4c4?MSPStoreType=image/gif&amp;s=44" alt="eyeball diameter | 0.83 inches (human: 0.94 in) eyeball volume | 0.31 in^3 (cubic inches) (human: 0.4 in^3) visual field | 250° (degrees) eardrum surface area | 46 mm^2 (square millimeters) (human: 55 mm^2) angle of auditory acuity | 2.5° (degrees) (human: 8.4°) upper limit of hearing ability | 140 kHz (kilohertz) (human: 21 kHz) olfactory epithelium receptor count | 2.3×10^8 (human: 3×10^7) olfactory epithelium surface area | 13 in^2 (square inches) (human: 0.39 to 0.78 in^2)" title="eyeball diameter | 0.83 inches (human: 0.94 in) eyeball volume | 0.31 in^3 (cubic inches) (human: 0.4 in^3) visual field | 250° (degrees) eardrum surface area | 46 mm^2 (square millimeters) (human: 55 mm^2) angle of auditory acuity | 2.5° (degrees) (human: 8.4°) upper limit of hearing ability | 140 kHz (kilohertz) (human: 21 kHz) olfactory epithelium receptor count | 2.3×10^8 (human: 3×10^7) olfactory epithelium surface area | 13 in^2 (square inches) (human: 0.39 to 0.78 in^2)" width="496" height="328"/&gt; &lt;/subpod&gt; &lt;subpod title="Internal organs"&gt; &lt;plaintext&gt; brain weight | 4.8 oz (ounces) (human: 2.6 to 3.3 lb) heart weight | 4.8 oz (ounces) (human: 11 oz) cardiac output | (120 to 180) in^3/min (inches cubed per minute) (human: 340 to 370 in^3/min) interior lung surface area | 970 ft^2 (square feet) (human: 970 ft^2) stomach capacity | 1.1 gallons digestive tract capacity | 1.8 gallons length of whole intestine | 16 feet (human: 20 to 26 ft) small intestine capacity | 55 fl oz (fluid ounces) large intestine and rectum capacity | 31 fl oz (fluid ounces) appendix capacity | 3 fl oz (fluid ounces) &lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP17991cd1c5fi21h72ac200005ec0d00i290h0gf3?MSPStoreType=image/gif&amp;s=44" alt="brain weight | 4.8 oz (ounces) (human: 2.6 to 3.3 lb) heart weight | 4.8 oz (ounces) (human: 11 oz) cardiac output | (120 to 180) in^3/min (inches cubed per minute) (human: 340 to 370 in^3/min) interior lung surface area | 970 ft^2 (square feet) (human: 970 ft^2) stomach capacity | 1.1 gallons digestive tract capacity | 1.8 gallons length of whole intestine | 16 feet (human: 20 to 26 ft) small intestine capacity | 55 fl oz (fluid ounces) large intestine and rectum capacity | 31 fl oz (fluid ounces) appendix capacity | 3 fl oz (fluid ounces)" title="brain weight | 4.8 oz (ounces) (human: 2.6 to 3.3 lb) heart weight | 4.8 oz (ounces) (human: 11 oz) cardiac output | (120 to 180) in^3/min (inches cubed per minute) (human: 340 to 370 in^3/min) interior lung surface area | 970 ft^2 (square feet) (human: 970 ft^2) stomach capacity | 1.1 gallons digestive tract capacity | 1.8 gallons length of whole intestine | 16 feet (human: 20 to 26 ft) small intestine capacity | 55 fl oz (fluid ounces) large intestine and rectum capacity | 31 fl oz (fluid ounces) appendix capacity | 3 fl oz (fluid ounces)" width="496" height="409"/&gt; &lt;/subpod&gt; &lt;subpod title=""&gt; &lt;plaintext&gt;(typical values, except where otherwise noted)&lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP18001cd1c5fi21h72ac200005210724bc1978f7h?MSPStoreType=image/gif&amp;s=44" alt="(typical values, except where otherwise noted)" title="(typical values, except where otherwise noted)" width="249" height="20"/&gt; &lt;/subpod&gt; &lt;states count="2"&gt; &lt;state name="Show metric" input="SpeciesDataPhysicalProperties__Show metric"/&gt; &lt;state name="More" input="SpeciesDataPhysicalProperties__More"/&gt; &lt;/states&gt; &lt;/pod&gt; &lt;pod title="Genome information" scanner="Data" id="GenomeSummary:SpeciesData" position="600" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt; total base pairs | 2445126910 total chromosomes | 39 known genes | 19528 known RNAs | 16953 known proteins | 33215 &lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP18011cd1c5fi21h72ac200006823c4b9b14245f8?MSPStoreType=image/gif&amp;s=44" alt="total base pairs | 2445126910 total chromosomes | 39 known genes | 19528 known RNAs | 16953 known proteins | 33215" title="total base pairs | 2445126910 total chromosomes | 39 known genes | 19528 known RNAs | 16953 known proteins | 33215" width="260" height="164"/&gt; &lt;/subpod&gt; &lt;states count="1"&gt; &lt;state name="Show details" input="GenomeSummary:SpeciesData__Show details"/&gt; &lt;/states&gt; &lt;/pod&gt; &lt;pod title="Image" scanner="Data" id="Image:SpeciesData" position="700" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext/&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP18021cd1c5fi21h72ac200004030c96gcgd02f40?MSPStoreType=image/gif&amp;s=44" alt="" title="" width="150" height="120"/&gt; &lt;/subpod&gt; &lt;/pod&gt; &lt;pod title="Species authority" scanner="Data" id="SpeciesAuthorithy:SpeciesData" position="800" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt;Linnaeus&lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP18031cd1c5fi21h72ac200002c691ead7fc4927e?MSPStoreType=image/gif&amp;s=44" alt="Linnaeus" title="Linnaeus" width="60" height="18"/&gt; &lt;/subpod&gt; &lt;/pod&gt; &lt;pod title="Other members of species Canis lupus" scanner="Species" id="SpeciesScannerOtherMembersOfSpecies" position="900" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext&gt; Canis lupus subsp. lupus | Canis lupus subsp. lycaon &lt;/plaintext&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP18041cd1c5fi21h72ac200000e76cgidc1b4a4fi?MSPStoreType=image/gif&amp;s=44" alt="Canis lupus subsp. lupus | Canis lupus subsp. lycaon" title="Canis lupus subsp. lupus | Canis lupus subsp. lycaon" width="345" height="18"/&gt; &lt;/subpod&gt; &lt;/pod&gt; &lt;pod title="Taxonomic network" scanner="Data" id="TaxonomyGraph:SpeciesData" position="1000" error="false" numsubpods="1"&gt; &lt;subpod title=""&gt; &lt;plaintext/&gt; &lt;img src="http://www4a.wolframalpha.com/Calculate/MSP/MSP18051cd1c5fi21h72ac200002ff8ihic491e8e59?MSPStoreType=image/gif&amp;s=44" alt="" title="" width="496" height="280"/&gt; &lt;/subpod&gt; &lt;states count="1"&gt; &lt;state name="Show as network" input="TaxonomyGraph:SpeciesData__Show as network"/&gt; &lt;/states&gt; &lt;/pod&gt; &lt;assumptions count="1"&gt; &lt;assumption type="Clash" word="dog" template="Assuming "${word}" is ${desc1}. Use as ${desc2} instead" count="3"&gt; &lt;value name="Species" desc="a species specification" input="*C.dog-_*Species-"/&gt; &lt;value name="DogBreedClass" desc="a class of dog breeds" input="*C.dog-_*DogBreedClass-"/&gt; &lt;value name="ExamplePage" desc="a general topic" input="*C.dog-_*ExamplePage-"/&gt; &lt;/assumption&gt; &lt;/assumptions&gt; &lt;sources count="2"&gt; &lt;source url="http://www.wolframalpha.com/sources/GenomeSequenceDataSourceInformationNotes.html" text="Genome sequence data"/&gt; &lt;source url="http://www.wolframalpha.com/sources/SpeciesDataSourceInformationNotes.html" text="Species data"/&gt; &lt;/sources&gt; &lt;/queryresult&gt; </code></pre> <p>I want to get the img src and display that image.</p>
    singulars
    1. This table or related slice is empty.
    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