Reputation: 1857
$string = 'ab!:;c+12,.3 €def-x/';
$string = preg_replace('/[^a-zA-Z0-9\s€+-]+/', '', $string);
$val=htmlentities($string, ENT_NOQUOTES, );
echo $string,"\n";
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.
Upvotes: 1
Views: 1750
Reputation: 522016
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.
Upvotes: 1
Reputation: 154513
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,"\n";
Should fix it.
Upvotes: 1