Attempting to convert Latin characters using htmlentities

76 Views Asked by At

I'm attempting to html encode various names, which are from all over the world. The system this is eventually going into cannot handle the raw characters itself, so I have to encode them first. htmlentities is working properly in 99% of cases, but I've come upon an exception and cannot make it work (I've tried every encoding option PHP lists). The characters in question are both latin (Ş and ş). Any suggestions on how to handle these exceptions? I'm using laravel, code below.

@foreach ($names as $name)
    {{ htmlentities($name) }}</br>
@endforeach
1

There are 1 best solutions below

0
Neberith On

The htmlentities() function is based on ISO-8859-1 characters table as default. You will have to give the encoding as an argument like this :

htmlentities($name, ENT_QUOTES, 'UTF-8')

You can choose which encoding you want in the list of the supported charset into the documentation.

Source : https://www.php.net/manual/en/function.htmlentities.php