Euro symbol in PHP ereg_replace

I want to allow the euro symbol in this regular expression, but it won’t go through

$val = ereg_replace($regex, "[^a-zA-Z0-9[:space:][:blank:]€+-]+", $_REQUEST[$var]); 
+4
source share
3 answers

In your comment, you forgot the delimiters required by preg_replace:

 $string = 'ab!:;c+12,.3 €def-x/'; $string = preg_replace('/[^a-zA-Z0-9\s€+-]+/', '', $string); echo $string,"\n"; 

exit:

 abc+123 €def-x 
+1
source

Do you have mbstring? If so, try using the mb_ereg_replace () function. It will support this character (even in UTF-8).

Edit: Also check if mbregex is enabled. Some hosts include mbstring but disables mbregex (I don't know why).

+5
source

Make sure the encoding used by your text editor / IDE is iso-8859-15 (if that is what you are trying to display).

If it is UTF-8 , you will have to perform another replacement, especially for it ( € , represented by several bytes, I assume that it will not fit into the regular expression [...] block).

BTW, ereg_replace() deprecated in favor of preg_replace() .

Plus, why do you have two "regex" options? (I assume $regex also contains a $regex ?)

A suggestion (unverified) if what you want to do is to remove the other + characters in your original regular expression:

 $val = preg_replace( array('/[^a-zA-Z0-9[:space:][:blank:]+\-]+/', '/€/'), '', $_REQUEST[$var] ); 
+1
source

Source: https://habr.com/ru/post/1398800/


All Articles