Solved

change ereg_replace into preg_replace problem

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

Title # Comments Views Activity
Wordpress French and English Site 6 74
How to display div value on input field value in php 11 51
Alert after MVC form submitted 1 22
Wordpress Query 5 24
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

792 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