1
我想從下面的代碼的IMG SRC標記特定的標籤:獲取從API代碼
<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>
我知道怎麼弄的明文信息,但我怎麼得到IMG SRC信息?這是我必須得到明文信息:
<?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";
}
?>
這不是Grabbing the href attribute of an A element重複,因爲我不能在我的Godaddy主機使用DOM。我已經嘗試過。
非常接近!我做了你的代碼,它只是一個數組[標題]的東西...所以我做了foreach($ pod1-> getSubpods()as $ subpod){print_r($ subpod-> image); }'代替atrributes和它給我' WAImage對象 ( [屬性] =>數組 ( [SRC] => http://www4b.wolframalpha.com/Calculate/ MSP/MSP7141hbbg7330dcd6h4f00002cb39d647363ei1g?MSPStoreType =圖像/ GIF&S = 55 [ALT] =>家犬 [標題] =>家犬 [寬度] => 139 [高度] => 18 ) )'現在我如何從t獲取src帽子? – user2362601 2013-05-08 14:24:45
@ user2362601根據轉儲:'$ subpod-> image-> attributes ['src']'應該可以工作 – Gordon 2013-05-08 14:33:57
謝謝Gordon !! – user2362601 2013-05-08 14:37:23