Wednesday, 15 April 2015

html - PHP regex for DOM Manupulation -



html - PHP regex for DOM Manupulation -

i trying text url. can help me.

$news1 = "http://www.espncricinfo.com/icc-womens-world-cup-2013/content/story/604808.html"; $a=preg_match_all("/\<p class\=['\"]news-body['\"]\>(.*?)\<\/p\>/",$news1,$b); echo $a; print_r($b[1]);

it homecoming 0 array(). if can help appreciated.

some html below:

<p class="news-body"> new zealand captain, suzie bates, spoke of how sides had played competitive game said intensity levels weren't same after dispiriting news came in. bates felt have been improve have not known result of other match. </p> <p class="news-body"> particularly shattering end holders england, went out of tournament without having had single poor game. defeats sri lanka , commonwealth of australia 1 wicket - off lastly ball - , 2 runs. edwards, however, refused offer excuses , said england had paid "slow start" tournament, origin shock loss sri lanka. </p> <p class="news-body"> "we had come here win tournament , haven't. haven't got final," edwards said. "that disappointing grouping of players. inconsistent in first phase of tournament , playing our best cricket, late. prepared well. have no excuses. didn't play well. didn't hold our catches against sri lanka." </p>

// fetch content $html = file_get_contents('http://www.espncricinfo.com/icc-womens-world-cup-2013/content/story/604808.html'); // load html dom $libxml_use_internal_errors = libxml_use_internal_errors(true); $dom = new domdocument; $dom->loadhtml($html); libxml_use_internal_errors($libxml_use_internal_errors); // note may ruin custom error handlers // load dom simplexml $simple = simplexml_import_dom($dom); // xpath document $news = $simple->xpath('//p[@class="news-body"]'); // echo results foreach($news $p) { echo "<p>$p</p>"; }

php html regex dom

No comments:

Post a Comment