Mauserrifle.nl Tech Articles

    Projects     Archive     Contact

PHP and replacing Euro signs

Within PHP it can be bit of a pain when you want to replace euro signs that come from a database query.

This problem mostly has to do with different encodes of text. It’s very hard to covert an euro sign with a hard “€” within your replace code. I came across this problem a lot of times. This website covers the euro sign regarding different codes on different platforms.

I found using the chr function can be very successful. The following code has proven itself to be work on different websites to replace a euro signs within a ISO String:

$string = str_replace(chr(128), 'EUR',$string);

For UTF-8:

$string = str_replace(chr(0xE2).chr(0x82).chr(0xAC),"EUR",$string);

Thanks for reading.

If you liked this post, you can share it with your followers or follow me on Twitter!