0

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']."'");
oliverbj
  • 4,983
  • 24
  • 72
  • 133

3 Answers3

1
  • 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).

Spudley
  • 157,081
  • 38
  • 222
  • 293
0

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');
Shankar Damodaran
  • 65,155
  • 42
  • 87
  • 120
0

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.

Bhavik Shah
  • 2,242
  • 1
  • 15
  • 32
CIRCLE
  • 3,695
  • 3
  • 32
  • 51