0

I need to print the following string but got another output in php.

   $test = "?s'd – b]zel/";
   echo $test;

and the output is:: ?s'd – b]zel/ I need the same string on output. The character '-' is special character in Nepali font. But, it's showing – instead of –. So, what will be the solution??

EDIT when i used json_encode($test), I got output "?s'd \u2013 b]zel/". But I dont need unicode, I need "?s'd – b]zel/" as output. What should I do??

Sandesh Sharma
  • 1,064
  • 5
  • 16
  • 32

4 Answers4

0

Make sure that you specify the charset of your page:

<meta charset="utf-8">

You need to make sure that every part of your application is UTF-8. Database connection, table data, page charset, etc. See this answer.

Community
  • 1
  • 1
Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66
0

I'm assuming you're running PHP on the console - if that's the case, you should change the console settings.

If you're running on the web - you should either change the page encoding or escape the character you're displaying. This can be done by adding the following to your HTML:

Gabi Lee
  • 1,193
  • 8
  • 13
  • You've got 2/3 wrong. Why would you assume he's running PHP on the console? Very few people do that, very **very** few beginners do that. Also, escaping your characters wouldn't help you in a charset problem. – Madara's Ghost Dec 06 '13 at 09:52
  • So did I. HTML escaping would solve nothing in this case, because the document itself might not be UTF8. If it *is*, and you're confident that the character in the document is the character you want displayed, then HTML escaping could work. But the base assumption is not necessarily correct. – Madara's Ghost Dec 06 '13 at 10:10
0

It's most likely because you use UTF8 encoded characters (so your is NOT "normal" dash - but at the same time your HTML document is not using UTF8 encoding, falling back to (usually) Latin1. Either "clean" your $test string, or fix HTML to correctly declare used encoding:

<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

Make sure that your document and HTML encoding are the same (recommended, UTF8).

Your PHP charset is set by the text editor you are using.

Your HTML charset can be determined by sending a header (which is the recommended way!)

header("Content-type: text/html; charset=utf-8");
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308