Jump to content

Converting a ereg_replace to preg_replace


adrianTNT

Recommended Posts

Can someone tell me how to convert this ereg_replace to preg_replace ?

 

$string = ereg_replace("[^A-Za-z0-9_]", " ", $string);

It is supposed to only allow letters and numbers.

 

Then I also need to replace multiple spaces that was like this:

$string = ereg_replace("( )+", "_", $string);

 

 

 

The main difference is that the preg_ functions need a delimitter around your regex.  Otherwise, the internal regex (if it worked before)  will work fine with preg_ equivalents although you might need to read up on the parameters and return values.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.