0

I have a php variable which has its value set from an HTML form. The value of the variable is

$x = rueFrédéricMistral

As you may see it has a special alphabet (e_tilda) in it.

Now when I echo x, it gives me the following: rueFr�d�ricMistral

I am not sure how to echo the original name. I tried the function htmlspecialchars() but it didn't work. On reading, what I understood that the function does not suit my case.

Can anyone help me on this please.

Thanks in advance. Neeraj

Francesco Montesano
  • 8,485
  • 2
  • 40
  • 64
Neeraj Saxena
  • 135
  • 1
  • 6

2 Answers2

0

you can also try this

echo htmlentities($x);

and also you can used this

for server side

<?php
    header('Content-Type: text/html; charset=ISO-8859-1');
?>

for client side

    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <?php
            $x = "rueFrédéricMistral";
            echo $x;
        ?>
    </body>
Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
  • I tried this and it is not working. However, the issue comes when I try to use $x in javascript. I wrote the following code in javascript: var abcd = ; alert(abcd).... But I get null in the alert message – Neeraj Saxena Oct 26 '17 at 13:20
0

There is at least 3 possible reasons:

  1. (most likely) you have incorrect charset definition into your html page, make sure that you have something like <meta charset="utf8"/> inside <head> section of your page
  2. It is possible that you have defined wrong charset for your database connection. Refer to documentation for functions / library that you're using to connect to database
  3. (unlikely) It is possible that contents inside database is broken by itself e.g. due to migration / inserting using invalid charset.
Flying
  • 4,422
  • 2
  • 17
  • 25