我正在寻找一种方法来找到外部网站的最后一个分页值。使用get_file_contents我得到以下结果,但我怎样才能获得值" 9"就在下一个
之前DOMElement Object ( [tagName] => ul
[schemaTypeInfo] => [nodeName] => ul
[nodeValue] => Prev 1 2 3 4 .. 9 Next
[nodeType] => 1 [parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted) [lastChild] => (object value omitted)
[previousSibling] => [attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] => [prefix] => [localName] => ul [baseURI] =>
[textContent] => Prev 1 2 3 4 .. 9 Next )
答案 0 :(得分:0)
如果我是你,我会首先将textContent与空格分开。然后答案是[Next Key - 1]。
$textContent = " Prev 1 2 3 4 .. 9 10 Next ";
$arr = explode(' ', $textContent);
if ($key = array_search('Next', $arr)) {
echo $arr[$key - 1];
}
// output : 10
答案 1 :(得分:0)
如果字符串末尾始终有Next
,您可能希望preg_match()
使用以下RegExp:([0-9]+) Next
nodeValue
键,如下所示:< / p>
$found = preg_match("#([0-9]+) Next#", $domElement['nodeValue'], $matches)
然后if ($found) {}
检查$matches[1]