sniped22 Posted May 26, 2007 Share Posted May 26, 2007 Another question so soon? yes! I need to parse through text that was entered by the user to find two words in a row, "Dealt to" so i find the "dealt to" line and after that is a word which I would like to change the color of. for example: Dealt to CheeseMan [X Y] // I would like to A) find this line b)change the text of //CheeseMan to blue C) represent X with x.jpg and y with y.jpg thanks again for all of your help! Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/ Share on other sites More sharing options...
AndyB Posted May 26, 2007 Share Posted May 26, 2007 http://ca.php.net/manual/en/function.strpos.php Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262324 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 as i am praticing RegEx $input = "We are PHP Freaks"; $find = "PHP"; $output = preg_replace('/('.$find.' )(\w+)/im', '$1<font color="#0000FF">$2<font>', $input ); echo $output; We are PHP <font color="#0000FF">Freaks<font> We are PHP Freaks Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262327 Share on other sites More sharing options...
sniped22 Posted May 27, 2007 Author Share Posted May 27, 2007 when I use strpos: $pos = strpos($ph, $findme); I am returned with the character's number. How do I go about editing the characters after that number? example: $pos returns 100, how do I go about editing character number 102? or at least how do I get the string that starts at the "D" in dealt to and ends with the "[" in [X Y] Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262333 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 use substr to grab the data either side etc.. did you try my regexp example? Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262337 Share on other sites More sharing options...
sniped22 Posted May 27, 2007 Author Share Posted May 27, 2007 regex seems waaaaaay too confusing. Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262345 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 all you need is the input and the find i have done the rest for you! i'll let you fiddle with substr + strpos as a note if you have PHP5 you can use stripos (ignores case) Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262355 Share on other sites More sharing options...
sniped22 Posted May 27, 2007 Author Share Posted May 27, 2007 nevermind, figured it out with substr. Thanks for the advice Mad and Andy. Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262357 Share on other sites More sharing options...
sniped22 Posted May 27, 2007 Author Share Posted May 27, 2007 just realized something: if i get the string "dealt to CheeseMan [<img src = x.jpg> <img src = y.jpg>]" how can i re-inject this into the "haystack" string at strpos's value? Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262367 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 No build a new string buy concatenating the extracts from substr Quote Link to comment https://forums.phpfreaks.com/topic/53106-search-for-string/#findComment-262386 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.