0

I have a PHP object displaying values as below when I use var_dump($obj):

object() (1) { ["name"]=> string(3) "" ... }

But when I print $obj->name, the browser displays "Lê" instead.

My browser is displaying UTF-8. HTML charset is also set to utf-8.

I tried with some functions but I didn't solve this.

could you please help me to solve this issue? Thanks.

EDIT:

I have already had all checked items as below:

  1. header('Content-Type: text/html; charset=utf-8');
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. My browser is displaying UTF-8
  4. The $obj is get from db table which set "character set" to utf-8 and "collation" to utf8_general_ci
  5. PHP file is encoded to UTF-8

enter image description here

Duc Le
  • 347
  • 1
  • 7
  • 12

1 Answers1

2

Set a UTF-8 header('Content-Type: text/html; charset=utf-8');.

I've just tested this on PHP5.4.8, nginx, Ubuntu 12.04 and Firefox. AFAIK, you'll get the same results in pretty much any PHP stack from at least the past 5 years.

<?php

$mystring = 'Lê';

print $mystring;

output: Lê

<?php

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

$mystring = 'Lê';

print $mystring;

output: Lê

Dan Blows
  • 20,846
  • 10
  • 65
  • 96
  • I did it. HTML meta tag charset is utf-8. But it doesn't solve the issue. – Duc Le Feb 06 '13 at 10:34
  • @Ducati You know this is not the same as a HTML meta tag, right? This is a header on the file itself. – Dan Blows Feb 06 '13 at 10:42
  • Hi Blowski, thanks for your response. I used that code. I can print 'Lê' as well as it displays correct in html. However my issue is that I can't display the property of object correctly. I updated my question with new information. Please see it. – Duc Le Feb 07 '13 at 02:05
  • Oop, I found my issue. I used function htmlentities() in __get(). So when I print the object property, it is encoded to ISO-8859-1 (default of this function with PHP prior to 5.4.0). Thanks for taking your time to help me. – Duc Le Feb 07 '13 at 02:50