Question

eregi_replace('[0-9]+\.+[0-9]','',$cart['unit']);

How to change it to preg_replace?

I get an error: Warning: preg_replace() [function.preg-replace]: Unknown modifier '+' in ---

Was it helpful?

Solution

You can use your existing Regex almost unchanged in a preg_replace(). Just add delimiters and a case-insensitive modifier. You get

preg_replace('#[0-9]+\.+[0-9]#i','',$cart['unit']);

In fact, the case-sensitivity is irrelevant since your pattern only matches 0-9 and .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top