replace all link href's with return of a function, with regex
- by Rajat Singhal
I have a function which returns a modified url, if passed a url..
I need to call this function on hrefs of all the links in my html data..
I can't use DomDocument, it's in php cli, I need regex solution..
I have tried preg_replace, and preg_replace_callback, but I simply don't understand the whole concept of using $1, $2 in the replacement string..If somebody can point to a good documentation,that'll be great too..
function modifyUrl($old_url) {
......
return $new_url;
}
$html = "...";//Long html content having links
//need to call modifyUrl for all link's hrefs..