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( '<a href="http://google.com">google</a>', '<a href="http://yahoo.com">yahoo</a>' );
$this->post['message'] = str_ireplace($word, $link, $this->post['message']);
Quote:
for example text
the output printed will be like this
HTML Code:
i love <a href="http://google.com">google</a> result
it is just replacing google text into a link like this <a href="http://google.com">google</a>
|
Quote:
but the problem is if the original google text is already inside a link, like this
HTML Code:
<a href="http://google.com">i love google result</a>
the output printed will be broken like this, there will be double hyperlink
HTML Code:
<a href="http://google.com">i love <a href="http://google.com">google</a> result</a>
|
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
__________________
Lets help each other
|