[How to] Exclude replacement inside hyperlinks, maybe using if statement,or other way

by 1 replies
2
Hi guys, below are simple script for word replacement, it is replacing a word in to link
PHP Code:
$word = array( 'google''yahoo' );  $link = array( 'google''yahoo' );   $this->post['message'] = str_ireplace($word$link$this->post['message']); 
please help guys, how to exclude the text google inside hyperlinks above from replaced, but the text google outside hyperlinks are still replaced maybe using if statement in the simple script above, or other way
#programming #exclude #hyperlinks #inside #replacement
  • [DELETED]
  • Hi Basketmen,

    You should use the strip_tags() function on your original word ($word) as follows:
    str_ireplace(strip_tags($word), $link, $this->post['message']);

    This will ensure that it's always plain text with no html tags.

Next Topics on Trending Feed

  • 2

    Hi guys, below are simple script for word replacement, it is replacing a word in to link PHP Code: $word = array( 'google', 'yahoo' );  $link = array( 'google', 'yahoo' );   $this->post['message'] = str_ireplace($word, $link, $this->post['message']);  for example text i love google result the output printed will be like this HTML Code: i love google result it is just replacing google text into a link like this google but the problem is if the original google text is already inside a link, like this HTML Code: i love google result the output printed will be broken like this, there will be double hyperlink HTML Code: i love google result please help guys, how to exclude the text google inside hyperlinks above from replaced, but the text google outside hyperlinks are still replaced maybe using if statement in the simple script above, or other way