0

我正在使用 cURL ping 导致 HTML 表的 API。我只想返回一个名为“errorCode”的字段的单个数字值。

(我正在使用 Jquery 来 ajax 我的 Curl.php 页面,它会 ping 一个 API,该 API 将回显到 curl 页面,从而在成功时将数字返回给我的 Jquery。大声笑是的)。

大部分都有效,除了我似乎无法解析 HTML 以获取我需要的唯一字段。我希望它是 XMl,但它不是。

我应该使用正则表达式来查找字段并提取其值吗?其他方式?

我的 CURL 页面的底部,它输出所有 HTML。我只需要提取名为“errorCode”的隐藏字段的值,然后回显到页面。

    $retValue = curl_exec($ch);                             
    echo $retValue;

$retValue 当前打印整个页面,包括 HTML 标签、表格标签等。

谢谢

4

1 回答 1

1

使用DOMDocumentDOMXPath

$dom = new DOMDocument();
$dom->loadHTML($retValue);
$path = new DOMXPath($dom);
$item = $path->query('/table/tr/td[errorCode]');//whatever the xpath is
$value = $item->item(0)->textContext;
于 2012-08-08T22:56:11.633 回答