Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从api代码中获取特定标记_Php_Html_Image_Tags_Src - Fatal编程技术网

Php 从api代码中获取特定标记

Php 从api代码中获取特定标记,php,html,image,tags,src,Php,Html,Image,Tags,Src,我想从以下代码中获取IMG SRC标记: <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://

我想从以下代码中获取IMG SRC标记:

<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";

}
?>


它不是的副本,因为我不能在我的Godaddy主机上使用DOM。我以前试过。

我以前从来没有用过那个狼毒血凝素。我想是这个:

如果是,请看一看

如您所见,它不仅具有纯文本的属性,还具有属性和其他内容的属性。这可能很容易

foreach ($pod1->getSubpods() as $subpod) {
    $attributes = $subpod->attributes;
    if (isset($attributes['src']) {
        echo $attributes['src'];
    }
}
但由于该图书馆的文献资料不存在,我无法确定。因此,如果这不起作用,只需
var\u dump
查看
$subpod
中包含的内容

同样,请查看其他类以了解它们的功能:


非常接近!我做了你的代码,它只产生了一个数组[title]东西…所以我做了
foreach($pod1->getSubpods()as$subpod){print\r($subpod->image);}
而不是atributes,它给了我` WAImage Object([attributes]=>array([src]=>[alt]=>Canis[title]=>Canis[width]=>139[height]=>18]`现在如何从中获取src?@user2362601根据转储:
$subpod->image->attributes['src']
应该可以工作
foreach ($pod1->getSubpods() as $subpod) {
    $attributes = $subpod->attributes;
    if (isset($attributes['src']) {
        echo $attributes['src'];
    }
}