2017-10-15 44 views
0

我正在尋找一種方法來查找外部網站分頁的最後一個值。使用get_file_contents我得到以下的結果,但我怎麼能得到的值「9」之前的下一步用php獲取分頁的最後一頁值file_get_contents

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

你可能想要在PHP中進行一些文本操作的搜索,以幫助你開始。 –

+0

如果在字符串末尾總是有一個「Next」,你可能想用下面的RegExp來'preg_match()': –

回答

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 
0

如果總是有一個Next在字符串的結尾,你可能想preg_match()有以下正則表達式:([0-9]+) NextnodeValue關鍵是這樣的:

$found = preg_match("#([0-9]+) Next#", $domElement['nodeValue'], $matches) 

然後if ($found) {}檢查什麼在$matches[1]