php - How to change url in html parser -
i have code output url ?tid=somenumbers
<?php include 'simple_html_dom.php'; // create dom url or file $html = file_get_html('http://news.sinchew.com.my/node'); // find links foreach($html->find('a') $element) { $tid = '?tid'; $url = 'news.sinchew.com.my/node'; if(strpos($element->href,$tid) && (strpos($element->href,$url))) { echo $element->href . '<br>'; } } ?> what wanted change ?tid=somenumbers ?tid=1234 , output url ?tid=1234 . stuck here hours,can me this?
try preg_replace perform substitutions based on regular expressions:
<?php //... echo preg_replace("/\\?tid=[0-9]+/", "?tid=1234", $element->href); //... ?>
Comments
Post a Comment