Solved

change ereg_replace into preg_replace problem

Posted on 2014-03-14
2
317 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now