Reputation: 6052
I am trying to do so foreign characters is showing correctly at my website.
When I try to write: "Português" it will output this:
Português
The code I use is:
$name = htmlspecialchars(stripslashes($f['forum_name']));
I also tried this:
$name = html_entity_decode(stripslashes(stripslashes($f['forum_desc'])));
But that gave me:
Português
What am I doing wrong?
Edit: $f is coming from this:
$sf=mysql_query("SELECT * FROM forum_cats WHERE forum_type='0' AND forum_type_id='".$h['forum_id']."'");
Upvotes: 0
Views: 83
Reputation: 4869
Try this:
<?php echo iconv(mb_detect_encoding($f['forum_name'], "UTF-8,ISO-8859-1"), "UTF-8", $f['forum_name']); ?>
Use mb_detect_encoding()
to detect the charset type of your strings and iconv()
to convert string to requested character encoding.
You can refer mb_detect_encoding and iconv on official documentation site.
Upvotes: 0
Reputation: 68466
Make use of utf-8 decode
<?php
echo utf8_decode("Português");//Português
EDIT : (From your latest question update) Add this on top of your PHP code.
<?php
ini_set('default_charset','utf-8');
mysql_set_charset('utf8');
header('Content-type: text/html; charset=utf-8');
Upvotes: 0
Reputation: 168655
First, make sure your PHP program file is saved with UTF-8 encoding. (a decent editor should allow you to set the encoding)
Second, make sure that your HTML code specifies UTF-8 encoding: Make sure you have the following meta tag in your HTML head:
<meta charset="UTF-8">
Thirdly, throw away all that entity decoding and especially throw away the stripslashes()
.
You may also need to do further work to make sure that everything in your system is using UTF-8 encoding (eg the database, other input files).
Upvotes: 1