I have some words Such as
"Hello this article about games. Our choice is train games. Name of game is My Little Train"
I want to add automatic links as below
"games" » "http://www.mywebsite.com"
"train games" » "http://www.myothersiteadrwesss.com"
"game" » "http://www.my3thsiteadress.com"
I tried it with PHP and str_replace but after my codes
"games" word has 2 links nested ("http://www.mywebsite.com" and "http://www.my3thsiteadress.com" )
"train games" word has 3 links nested (all 3 links)
How can I solve my problem?
finally i want
<a href="http://www.my3thsiteadress.com">game</a>
<a href="http://www.myothersiteadrwesss.com">train games</a>
<a href="http://www.mywebsite.com">games</a>
words count can be change
I think you should use preg_replace instead of str_replace. That way, you can specify a much stricter regexp to be replaced (Somewhat like a "match whole word"). Here, take a look at http://php.net/manual/es/function.preg-replace.php)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With