replace all link href's with return of a function, with regex

Posted by Rajat Singhal on Stack Overflow See other posts from Stack Overflow or by Rajat Singhal
Published on 2012-09-06T09:31:32Z Indexed on 2012/09/06 9:38 UTC
Read the original article Hit count: 320

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..

© Stack Overflow or respective owner

Related posts about php

Related posts about hyperlink