Monkuar Posted December 6, 2011 Share Posted December 6, 2011 $replace = array(""=>"<img src=html/emoticons/smile.gif>", "2"=>"b", "3"=>"c", "4"=>"d", "5"=>"e"); $txt = preg_replace("'(|2|3|4|5)'e", '$replace["\1"]', $txt, 3); I am trying to put in the regex pattern, but it works, but it's letting me use more then just "3", I need to edit the ("'(|2|3|4|5)'e", '$replace["\1"]', $txt, 3) Code so I can get the " " to work correctly. I tried: ("'(:\)|2|3|4|5)'e", '$replace["\1"]', $txt, 3) But still is letting me post more then 3. I tried: ("'(\:\)|2|3|4|5)'e", '$replace["\1"]', $txt, 3) With 2 \'s but still wont work. Any help guys? :confused: Quote Link to comment Share on other sites More sharing options...
neuroxik Posted December 7, 2011 Share Posted December 7, 2011 I had trouble understanding what you were asking for, but if you want to convert the to the smiley GIFs, but only the first 3 found in $txt, and the rest just represented as text, escaping it ( :\) )worked on my side: $txt = "Bla bla ya no maybe please 1 2 3 4 5 nada"; $replace = array(""=>"<img src=html/emoticons/smile.gif>", "2"=>"b", "3"=>"c", "4"=>"d", "5"=>"e"); $txt = preg_replace("'(:\)|2|3|4|5)'e", '$replace["\1"]', $txt, 3); echo $txt; // outputs: Bla bla <img src=html/emoticons/smile.gif> ya <img src=html/emoticons/smile.gif> no <img src=html/emoticons/smile.gif> maybe please 1 2 3 4 5 nada You said you tried it and it didn't work on your side, just letting you know THIS (quoted above) works on my side. Quote Link to comment Share on other sites More sharing options...
xyph Posted December 7, 2011 Share Posted December 7, 2011 No idea what you are looking to accomplish. Quote Link to comment Share on other sites More sharing options...
Monkuar Posted December 7, 2011 Author Share Posted December 7, 2011 I had trouble understanding what you were asking for, but if you want to convert the to the smiley GIFs, but only the first 3 found in $txt, and the rest just represented as text, escaping it ( :\) )worked on my side: $txt = "Bla bla ya no maybe please 1 2 3 4 5 nada"; $replace = array(""=>"<img src=html/emoticons/smile.gif>", "2"=>"b", "3"=>"c", "4"=>"d", "5"=>"e"); $txt = preg_replace("'(:\)|2|3|4|5)'e", '$replace["\1"]', $txt, 3); echo $txt; // outputs: Bla bla <img src=html/emoticons/smile.gif> ya <img src=html/emoticons/smile.gif> no <img src=html/emoticons/smile.gif> maybe please 1 2 3 4 5 nada You said you tried it and it didn't work on your side, just letting you know THIS (quoted above) works on my side. Thank you for your help,topic solved. 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.