note 26911 deleted from function.preg-replace by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 22:04:40 +0000 |
| Subject: | note 26911 deleted from function.preg-replace by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55697@lists.php.net to get a copy of this message | ||
Note Submitter: rbach@westman.wave.ca
----
I have used this following code to strip out all domain instances from all links of a web-page and
replace it with my own chosen domain name. It works fine but all image tagged web links are not
replaced with my chosen domain name and remain the same.
I need help to add this part of the code with this script.
Here is the code which I got from here and modified somewhat;
$code = preg_replace("'<a
href=[\"|\'](.*[^>])[\"|\']>(.*[^<>])</a>'i",
"<a href=\"http://www.yoursitehere.com\\1\">\\2",$code);//all
links will be changed to yoursitehere
$search = array("'&(lt|#60);'i", "'&(gt|#62);'i");
$replace = array("<",">");
$code = preg_replace($search, $replace, $code);
Hope this helps someone! I use this to fetch webpages and change all the links back to the original
links while in my domain. I also want to add the feature of "target=_blank" to all the
links so that all hyperlinks will load in a new window.