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

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -