Replace specified link tag in text


/ Published in: PHP
Save to your folder(s)

Affects <A> tags for links starting with $link
Example: LinkReplacer ($text, 'http://www.snipplr.com') affects to
<a href="http://www.snipplr.com">Snipplr</a>
and <a href="http://www.snipplr.com/blog">Snipplr Blog</a>


Copy this code and paste it in your HTML
  1. function LinkReplacer($text, $link, $new_text)
  2. {
  3. $quoted_link = preg_quote($link,'/\'');
  4. $regexp = '/<a [^<]*href=["|\']?'.$quoted_link.'["|\']?[^>]*>.*<\\/a>/ui';
  5. $text=preg_replace($regexp, $new_text, $text);
  6. return $text;
  7. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.