次のコードを使用して、別の Web サイトから div を抽出しようとしています。
<?php
$doc = new DomDocument;
//We need to validate our document before refering to the id
$doc->validateOnParse = true;
$doc->loadHtml(file_get_contents('http://myaddresshere'));
var_dump($doc->getElementById('the div'));
?>
結果を取得できますが、その前に長いphpコード文字列も取得しています:
object(DOMElement)#2 (18) { ["tagName"]=> string(2) "h3" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(2) "h3" ["nodeValue"]=> string(35) "Telephone Technical Support: Active" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> string(22) "(object value omitted)" ["nextSibling"]=> string(22) "(object value omitted)" ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(2) "h3" ["baseURI"]=> NULL ["textContent"]=> string(35) ***"Telephone Technical Support: Active"*** }
その文字列をすべて削除して、div のコンテンツのみを取得するにはどうすればよいですか。
- 問題の div は、ブール値の結果 (アクティブ/期限切れ) を示しています