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
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.

Link to comment
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.

 

Thank you for your help,topic solved.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.