PHP
1$html = file_get_contents($content_dir.$line); 2$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'ASCII, JIS, UTF-8, EUC-JP, SJIS'); 3 4$domDocument = new DOMDocument(); 5libxml_use_internal_errors( true );//http://qiita.com/mgng/items/ffe82b5a0c3186770249 6$domDocument->loadHTML($html); 7libxml_clear_errors(); 8$xmlString = $domDocument->saveXML(); 9$xmlObject = simplexml_load_string($xmlString); 10 11//本文全体 12$array_excerpt = $xmlObject->xpath("//div[@class='content']"); 13 14//抜粋 15$excerpt = $img_path ? '<p>'.$array_excerpt[0]->p[1].'</p>' : '<p>'.$array_excerpt[0]->p[0].'</p>'; 16
HTML
1<p class="top">sample<a href="#" title="hoge">hoge</a>sample</p>
SimpleXMLで本文の抜粋を表示させるコードを書いているのですが、このコードでは抜粋のpタグの中にリンク等があっても取得できません。再帰的に子要素までを取得して$excerpt
に入れる方法はないでしょうか
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/28 07:14
2017/02/28 07:30