2017-10-15 33 views
0

私は、外部のウェブサイトのページングの最終価値を見つける方法を探しています。使用get_file_contentsで、私は次のような結果を得ていますが、どのように私は私があなただったら次はページの最終ページの値をPHPのファイル_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を分割する値「9」の直前に取得することができます。答えは[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()する場合があります。このようなnodeValueキーに([0-9]+) Next

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

その後if ($found) {}チェックが$matches[1]に何

関連する問題