Jump to content

Argh! stupid Regex crap!


Monkuar

Recommended Posts

$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: :confused: :confused:

Link to comment
https://forums.phpfreaks.com/topic/252622-argh-stupid-regex-crap/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.