0

I have this code that output all url with ?tid=someNumbers

<?php
include 'simple_html_dom.php';
// Create DOM from URL or file
$html = file_get_html('http://news.sinchew.com.my/node');


// Find all links 
foreach($html->find('a') as $element) {
       $tid = '?tid';
       $url = 'news.sinchew.com.my/node';
       if(strpos($element->href,$tid) && (strpos($element->href,$url))) {
           echo $element->href . '<br>';
       }
}
?>

What i wanted to do is change ?tid=someNumbers to ?tid=1234 and then output all url with ?tid=1234 . I stuck here for hours,can someone help me with this?

1
  • what criteria does the href attribute have to meet? Commented Sep 4, 2013 at 15:06

1 Answer 1

2

Try preg_replace to perform substitutions based on regular expressions:

<?php

//...

echo preg_replace("/\\?tid=[0-9]+/", "?tid=1234", $element->href);

//...

?>
Sign up to request clarification or add additional context in comments.

1 Comment

thanx ! all url have tid=1234. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.