RyanSF07 Posted January 12, 2013 Share Posted January 12, 2013 Hello, This code: $textlevel= $row['level_text']; $oldlevel = array("Intermédio", "Intermédio avançado"); $newlevel = array("intermediate", "high_intermediate"); $textlevel = str_replace($oldlevel , $newlevel , $textlevel); spits out "intermediate avançado" instead of "high_intermediate" How do I join "Intermédio" and "avançado" so that "Intermédio avançado" is in fact replaced with high_intermediate instead of only the first work replaced? thank you for your help, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/273075-replacing-two-words/ Share on other sites More sharing options...
Jessica Posted January 12, 2013 Share Posted January 12, 2013 In the future you should show us the actual string as well. Switch the order of the elements in the array. Quote Link to comment https://forums.phpfreaks.com/topic/273075-replacing-two-words/#findComment-1405230 Share on other sites More sharing options...
Love2c0de Posted January 12, 2013 Share Posted January 12, 2013 (edited) Hey bud, you can give this a try: <?php $textlevel= "Intermédio"; $words = str_word_count($textlevel,0,"éç"); if($words == 2) { $textlevel = str_replace("Intermédio avançado","high_intermediate",$textlevel); } else { $textlevel = str_replace("Intermédio","intermediate",$textlevel); } echo $textlevel; ?> Just wrote it works pretty well. EDIT: LOL just do what jessica said. Hope this helps you, Regards, L2c. Edited January 12, 2013 by Love2c0de Quote Link to comment https://forums.phpfreaks.com/topic/273075-replacing-two-words/#findComment-1405232 Share on other sites More sharing options...
RyanSF07 Posted January 12, 2013 Author Share Posted January 12, 2013 Well I'll be darn. Thanks Jessica. Quote Link to comment https://forums.phpfreaks.com/topic/273075-replacing-two-words/#findComment-1405233 Share on other sites More sharing options...
Jessica Posted January 12, 2013 Share Posted January 12, 2013 NP. To prevent this problem most token/merge code systems use a marker to denote the start and end of a token/code. You can use things like __, :, @@, etc. Quote Link to comment https://forums.phpfreaks.com/topic/273075-replacing-two-words/#findComment-1405239 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.