
January 30th, 2009, 04:46 AM
|
|
Contributing User
|
|
Join Date: Aug 2003
Posts: 235
  
Time spent in forums: 2 Days 7 h 12 m 32 sec
Reputation Power: 14
|
|
|
Identify external links in a string and add text to them
Guys and girls,
I'm using PHP. I usually like to work these things out myself but I'm totally stuck.
Taking a clump of text e.g. from a CMS entry, I want to check all the links in the text and for those that do not contain
"folder1/folder2"
in the URL path I want to add the text along the lines
"(this link will take you away from this section)"
to the text in the anchor tag, for all links in the text provided.
E.g.
Code:
<a href="some/other/place">my link</a>
would become
Code:
<a href="some/other/place">my link (this link will take you away from this section)</a>
I got as far as this for the expression:
PHP Code:
preg_match('/<a.+href=".*folder1/folder2.*".*>.+</a>/i', $testString)
but couldn't even get that to work...
Really appreciate some help with this. Many thanks.
__________________
Time isn't wasted if you're wasted all the time
|