Horst Azeglio Posted January 8, 2007 Share Posted January 8, 2007 I'm trying to convert ever lowercase word "i" into an uppercase word I.Here's my code.[quote]$string="This is my string. i am a regular expression illiterate";$string=preg_replace("/[ \,\.!\?\']i[ \,\.!\?\']/","/[ \,\.!\?\']I[ \,\.!\?\']/",$string);[/quote] Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 8, 2007 Share Posted January 8, 2007 if you are simply changing i to Ithen this:str_replace("i","I",$string);would workTed Quote Link to comment Share on other sites More sharing options...
Horst Azeglio Posted January 8, 2007 Author Share Posted January 8, 2007 I think it wouldn't work because it would also replace the i letter inside words.btwI just noticed the regex forum. I should have posted that topic in it. If a mod moves it I wont be confused. Quote Link to comment Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 Try [tt]/\bi\b/[/tt]. Quote Link to comment Share on other sites More sharing options...
Horst Azeglio Posted January 8, 2007 Author Share Posted January 8, 2007 thanks a lot, super guru, it works perfectly, however, I don't understand the use of the backslash in that context. Can someone explain me why does it work? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 8, 2007 Share Posted January 8, 2007 [url=http://regular-expressions.info/wordboundaries.html]Word Boundaries[/url] Quote Link to comment Share on other sites More sharing options...
Horst Azeglio Posted January 8, 2007 Author Share Posted January 8, 2007 thanks, I'm gonna read that 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.