French replace special characters PHP / HTML

Here is some basic code, not a function, that is replacing the special characters from the french language.

Whatever you do, if you load these characters in a browser, they will look weird.

By replacing them (using this basic code), they will look normal in the browser.

1
2
3
$french_replace = array("à", "â", "æ", "ç", "è", "é", "ê", "ë", "î", "ï", "ô", "œ", "ù", "û", "ü");
$french_replace_with = array("à", "â", "æ", "ç", "è", "é", "ê", "ë", "î", "ï", "ô", "œ", "ù", "û", "ü");
$string = str_replace($french_replace, $french_replace_with, $string);

Outside of that, be sure to have these html tags in your html file.

2
3
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8" />

ADD A COMMENT: