views:

1745

answers:

3

i have the following javascript code:

http://www.nomorepasting.com/getpaste.php?pasteid=22561

Which works fine(the makewindows function has been changed to show it is a php variable), however the html contains unicode characters, and will only be assigned characters leading up to the first unicode character. If I make a small test file and echo out article_desc directly, all the html is output, although quetsions marks are displayed instead of the correct symbols. However json_encode seems to cut short the html, resulting in errors.

edit: here is a dump straight from the mysql database of the html I am trying to display:

http://www.yousendit.com/download/TTZueEVYQzMrV3hMWEE9PQ

it says utf-8 in the source. the actual page code generated from echoing out article_desc is here:

http://www.nomorepasting.com/getpaste.php?pasteid=22566

it is definitely the same record, so I am unsure why it seems to very different.

edit: this was fixed by calling: mysql_query('SET NAMES utf8');

A: 

i don't think you need json_encode. json_encode encodes PHP arrays and objects to readable JavaScript format. If you send plain text or html within ajax you don't need json_encode

Irmantas
json_encode will also handle stuff like escaping quotes for you
Tom Haigh
my bad you right :)
Irmantas
+1  A: 

json_encode expects strings to be UTF-8 encoded byte streams. You'll have to either use utf-8 encoded strings internally (Which is the only current way to deal with unicode characters in PHP anyway), or use a different library for generating json.

troelskn
Is there a way to convert the data or insert it into the mysql database as unicode?
Joshxtothe4
I cannot use Zend.
Joshxtothe4
You can convert latin1 strings (Which is the default for php5), using utf8_encode(). Why is it that you can't use Zend Framework components?
troelskn
+1  A: 

json_encode(utf8_encode($Content));

this will solve your issue

Not if you want to encode an array
Typeoneerror