Jump to content

Switching from ereg_replace to preg_match syntax help


TheBrandon

Recommended Posts

Hello all,

 

I need to switch my code from ereg_replace to preg_match but I'm having trouble figuring out how to get the syntax right for this and keep the same functionality.

 

$vendor_ID = ereg_replace("^\*","",$key);

 

Any advice on how to maintain this functionality but use non-deprecated methods?

Yeah I've tried these:

$subcat_ID = preg_match("\^\*\","",$key);	

$subcat_ID = preg_match("\^\*\",$key);

$subcat_ID = preg_match("/^\*/","",$key);	

$subcat_ID = preg_match("/^\*/",$key);

 

They all generate errors. That's why I'm asking for help.

Oh snap, you're right.

 

I still need help with the syntax though. I'm still learning expressions like this. I've tried:

$vendor_ID = preg_replace("^\*","",$key);

$vendor_ID = preg_replace("\^\*","",$key);	

$vendor_ID = preg_replace("\^\*\","",$key);	

 

None seem to work?

So you're trying to replace an * at the beginning of the string?  for simple stuff, the only modification to an ereg pattern to get to PCRE is to add delimiters.  Here I use /

 

$vendor_ID = preg_replace("/^\*/", "", $key);

preg_replace("/^\*/" ... will work. You were close earlier, just using the wrong function. 

 

Please take the time to read through the documentation (start here: PCRE functions) to familiarise yourself with this new set of functions.

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.