surfwtw Posted March 3, 2012 Share Posted March 3, 2012 I am using preg_replace to automatically bold "$word" when it appears. It will only replace the word when capitalized. How can I get it to replace the word without being case sensitive. Also could I also throw a link in? I tried and I get a syntax error. I'm guessing the links in PHP are different than HTML Here is my code <?php $find ="/$word/"; $replace ="<b>$word</b>"; Echo preg_replace ($find, $replace, $definition); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258154-preg_replace-i-dont-want-it-to-be-case-sensitive/ Share on other sites More sharing options...
QuickOldCar Posted March 3, 2012 Share Posted March 3, 2012 $find ="/$word/i"; //note the i for insensitive Quote Link to comment https://forums.phpfreaks.com/topic/258154-preg_replace-i-dont-want-it-to-be-case-sensitive/#findComment-1323362 Share on other sites More sharing options...
surfwtw Posted March 3, 2012 Author Share Posted March 3, 2012 WOW THANKS. That is so much more simple than the code I was using before. OKay, is there any way I can also make it a link? Quote Link to comment https://forums.phpfreaks.com/topic/258154-preg_replace-i-dont-want-it-to-be-case-sensitive/#findComment-1323364 Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 Do you mean converting the text that you find into a link? You already have the right idea with your idea converting it into bold, except you would just do <?php $find ="/$word/i"; $replace ="<a href='page.php'>$word</a>"; Echo preg_replace ($find, $replace, $definition); ?> or do go a bit further, perhaps you want the text to be converted into a clickable link that goes to a page that searches for that term? <?php $find ="/$word/i"; $replace ="<a href='search.php?search=$word'>$word</a>"; Echo preg_replace ($find, $replace, $definition); ?> is that what you meant? Quote Link to comment https://forums.phpfreaks.com/topic/258154-preg_replace-i-dont-want-it-to-be-case-sensitive/#findComment-1323365 Share on other sites More sharing options...
surfwtw Posted March 3, 2012 Author Share Posted March 3, 2012 Yes that worked. The only problem is that I actually have thousands of links Thanks Quote Link to comment https://forums.phpfreaks.com/topic/258154-preg_replace-i-dont-want-it-to-be-case-sensitive/#findComment-1323554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.