• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

change ereg_replace into preg_replace problem

Hi experts,

I change all my ereg_replace into preg_replace but I have a line where I am not sure if this is going to work so easy. How ever I cant test it either very well because I am not even sure what this line does.

the original line is:
$value = ereg_replace('(&#[0]*58;|&#[xX][0]*3[aA];|\\\\[xX][0]*3[aA];|\\\\[uU][0]*3[aA];)', '', $value);

and I thought I change to:
$value = preg_replace('/(&#[0]*58;|&#[xX][0]*3[aA];|\\\\[xX][0]*3[aA];|\\\\[uU][0]*3[aA];)/', '', $value);

would this be correct? (placed a / before and in the end of the regex)
thanks...
0
Oliver2000
Asked:
Oliver2000
1 Solution
 
gr8gonzoConsultantCommented:
It looks correct, but it's a little confusing as to the final goal of the regular expression. If you want to test it, try out The Regex Coach. Just google for it - it's a free app and makes it pretty easy to test out regexes as you type them. You just have to remember to remove any extra double slashes that you'd put in for PHP.

So the above regex would look like this in Regex Coach:
(&#[0]*58;|&#[xX][0]*3[aA];|\\[xX][0]*3[aA];|\\[uU][0]*3[aA];)

If you want a target string / example to test against, you could use this:
H:e: :l:l:l\x03a; \X003A;o\u03a; \U3a;World!

If you do the replacement, you should end up with:
Hello World!

The regex seems to just try and replace encoded colon : characters (encoded as either html or unicode or hex entities). Not quite sure why, but that's what it's doing.
0
 
Oliver2000Author Commented:
Thanks, your tip with the Regex Coach is perfect. thx.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now