PHP欧元符号htmlentities

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

Echos

abc+123 �def-x

And not

abc+123 €def-x

I need to get the Euro symbol through a Regex and into the database but not as the Euro symbol.

Try:

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

Should fix it.

You'll need to supply the u modifier for the regex, otherwise it doesn't handle Unicode characters:

preg_replace('/.../u', ...)

If you do so, make sure the source code and text is encoded in UTF-8.