2017-10-15 2 views
0

나는 외부 웹 사이트의 페이지 매김의 마지막 가치를 찾는 방법을 찾고 있습니다. 사용 get_file_contents으로 나는 다음과 같은 결과를 얻고 있지만 방법은 내가 당신이라면 다음이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을 분할 할 것 값 "9"직전 얻을 수 있습니다. 그러면 대답은 [Next Key - 1]이 될 것입니다. 문자열의 끝에서 항상 Next가있는 경우

$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

, 다음과 같은 정규식으로 preg_match()에 할 수 있습니다 : ([0-9]+) Next을 같은 nodeValue 키 :

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

그런 if ($found) {} 체크 $matches[1]에 무엇이