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, '') affects to
<a href="">Snipplr</a>
and <a href="">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


RSS Icon Subscribe to comments

You need to login to post a comment.