Solved

change ereg_replace into preg_replace problem

Posted on 2014-03-14
2
330 Views
Last Modified: 2014-03-14
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
Comment
Question by:Oliver2000
2 Comments
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 39929871
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
 

Author Closing Comment

by:Oliver2000
ID: 39929966
Thanks, your tip with the Regex Coach is perfect. thx.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question