PHP special characters replace option

Skythrust

Member
Jul 9, 2019
133
7
Hi there,

I have an PHP page which is showing names from a database table. over here there are special characters é,á,ö etc.

I would like to replace them for "normal" letters. I have tried to convert them with;
$output = iconv("utf-8", "ascii//TRANSLIT", $input);

but that doesn't work for me.

Example; Ok� it should be Oké

How can I solve this?
 

Raizer

Active Member
Feb 21, 2019
145
76
1 - Replace your
<meta charset="utf-8">
with
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

2 - Check if your HTML Editor's encoding is in UTF8. Usually this option is found on the tabs on the top of the program, like in Notepad++.
3 - Check if your browser is compatible with your font, if you're somehow importing a font. Or try and add a css to set your fonts to a default/generally accepted one like

body
{
font-family: "Times New Roman", Times, serif;
}

Hope it helps :)
 

Skythrust

Member
Jul 9, 2019
133
7
1 - Replace your

with


2 - Check if your HTML Editor's encoding is in UTF8. Usually this option is found on the tabs on the top of the program, like in Notepad++.
3 - Check if your browser is compatible with your font, if you're somehow importing a font. Or try and add a css to set your fonts to a default/generally accepted one like



Hope it helps :)


Thanks!, default I use not a font for now. I have changed these things above. But still the same issue.
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
The problem is likely that your server, that serves the PHP files, does so with the wrong encoding. You can see this in browser DevTools (Chrome, Firefox, Edge, etc.) under the Network tab. If you click on the item that is the page itself, you can see the headers that are sent from the server:

You must be registered for see images attach


Open DevTools (F12):

  1. Click on the Network tab.
  2. Click on Doc in the filter list.
  3. Click on the page that corresponds with the current page (see the URL, for example)
  4. Find the Content-Type field and make sure it is text/html; charset=utf-8.
If this doesn't work there are two ways to fix it. The simplest way, but not the best as it requires you to do this for all pages, is to put the following line in top of every PHP script:

PHP:
header('Content-Type: text/html; charset=utf-8');

This should be put before outputting any content (echo, print, HTML, etc.).

A better way that will solve this problem across all scripts is to change your the configuration of PHP. You can find the location of the php.ini file by creating a PHP file with the code:

PHP:
<?php phpinfo(); ?>

This will output info about your PHP instance. Look for "Loaded Configuration File". Open the file at that location, and find the setting default_encoding—the setting may be commented out with a semi-colon. Just replace the whole line with the following:

INI:
default_charset = "utf-8"

Restart your web server and see if it works. With this configuration you wont need any settings or send headers, like the first way, as it automatically sets the correct encoding.
 
Last edited:

Users who are viewing this thread

Top