Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace ereg_replace with preg_replace [duplicate]

Hi need to change the function ereg_replace("[\]", "", $theData) to preg_replace

like image 966
user359187 Avatar asked Sep 06 '10 06:09

user359187


1 Answers

To port ereg_replace to preg_replace you need to put the regex between a pair of delimiter

Also your regx is [\] is invalid to be used for preg_replace as the \ is escaping the closing char class ]

The correct port is

preg_replace('/[\\\]/','',$theData) 

Also since the char class has just one char there is no real need of char class you can just say:

preg_replace('/\\\/','',$theData) 

Since you are replace just a single char, using regex for this is not recommended. You should be using a simple text replacement using str_replace as:

str_replace('\\','',$data);
like image 66
codaddict Avatar answered Oct 14 '22 14:10

codaddict