간단한 작업을 수행하고 싶습니다. 문자열의 일부 (HTML 파일)에서 코드의 특정 부분을 추출합니다. 예를 들어문자열의 하위 문자열을 모두 가져옵니다.
:
//Get a string from a website:
$homepage = file_get_contents('http://mywebsite.org');
//Then, search a particulare substring between two strings:
echo magic_substr($homepage, "<script language", "</script>");
//where magic_substr is this function (find in this awesome website):
function magic_substr($haystack, $start, $end) {
$index_start = strpos($haystack, $start);
$index_start = ($index_start === false) ? 0 : $index_start + strlen($start);
$index_end = strpos($haystack, $end, $index_start);
$length = ($index_end === false) ? strlen($end) : $index_end - $index_start;
return substr($haystack, $index_start, $length);
}
내가 싶어 출력,이 경우, 페이지의 모든 스크립트. 그러나 제 경우에는 첫 번째 스크립트 만 얻을 수 있습니다. 나는 재귀가 없기 때문에 그것이 옳다고 생각한다. 그러나 나는 이것을하는 가장 좋은 방법이 무엇인지 모른다! 어떤 제안?
강아지는 무섭게 당신이 [DOM 파서]를 사용하지 않는 때마다 스탬프 (http://php.net/manual/en/book.dom.php) 물건을 찾기 위해 html 문서에서. – moonwave99
안녕하세요. 나는 "max_nested_level"문제가있는 Simple Dom Parser로 시도했다. 그래서이 방법으로 움직였다 :) – alessandronos
max_nested_level의 문제점은 무엇인가? 나는 PHP Simple HTML Dom Parser가 그렇게 할 수 있다고 믿는다. – raygo