rockinaway Posted February 10, 2007 Share Posted February 10, 2007 FOr my search I am highlighting matches.. and I have one problem. I am using: str_replace($_GET['keywords'], 'MY HIGHLIGHT CODE', $search results) However with this is the search term was 'test', then it only highlights 'test', and not similar words like 'Test' etc Is there anyway this can be solved? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 http://us3.php.net/str_replace See also str_ireplace(), substr_replace(), preg_replace(), and strtr(). Try that first one. i in a function like that normally indicated case-Insensitive Quote Link to comment Share on other sites More sharing options...
rockinaway Posted February 11, 2007 Author Share Posted February 11, 2007 Thanks! I guess I need the str_ireplace Thanks again! Quote Link to comment Share on other sites More sharing options...
rockinaway Posted February 11, 2007 Author Share Posted February 11, 2007 I am getting undefined function with using str_ireplace Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 11, 2007 Share Posted February 11, 2007 str_ireplace is only available for PHP5. You're probably better of using ergei_replace instead. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted February 11, 2007 Author Share Posted February 11, 2007 Doesn't recognise it still :S Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 11, 2007 Share Posted February 11, 2007 What doesn't it recognise? ergei_replace or str_ireplace? Quote Link to comment Share on other sites More sharing options...
rockinaway Posted February 11, 2007 Author Share Posted February 11, 2007 Both :'( Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 11, 2007 Share Posted February 11, 2007 Ooh hang on, I had a slight typo it should be eregi_replace not ergei_replace Before using this function read the document on it here Quote Link to comment Share on other sites More sharing options...
rockinaway Posted February 11, 2007 Author Share Posted February 11, 2007 I don't get the pattern thing and how to work it out if I am using $_GET['keywords'] EDIT - Doesn't recognise that either Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 12, 2007 Share Posted February 12, 2007 SO this doesn't work: <?php if(isset($_GET['keyword'])) { $keyword = $_GET['keyword']; $txt = 'Hello world how are you today?'; $txt = eregi_replace('(' . $keyword. ')', "<b style=\"color: red;\">\\0</b>", $txt); echo $txt; } ?> <form action="" method="get"> Keyworld: <input type="text" name="keyword" value="hello"><br /> <input type="submit" value="Highlight Keyword"> </form> When you use ereg you are using regular expressions. So you're best of reading up on the basics of regular expressions in or der to understand. Also you're best of readin up on how the ereg function works too, before I linked you to the eregi function which doesnt explain how ereg works. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted February 13, 2007 Author Share Posted February 13, 2007 That works now... Thanks! I don't get the \\0 and couldn't find anything on it :S Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 13, 2007 Share Posted February 13, 2007 its a back reference. If you read how the ereg function worked it explains it there. Quote Link to comment 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.