?
Solved

change ereg_replace into preg_replace problem

Posted on 2014-03-14
2
Medium Priority
?
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 2000 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

777 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