PHP: To decode json to chinese and smily not works? [duplicate] - php

This question already has answers here:
Unicode character in PHP string
(8 answers)
Closed 8 years ago.
To decode json to chinese:
json_decode('"\ud83d\ude18\ud83d\ude18\ud83d\ude18\ud83d\ude18\u597d\u5bb6\u4f19\ud83d\ude0d\ud83d\ude0d\ud83d\ude0d"');
not works?
It works for chinese but not for smily
can you please give me any idea for it

that's not a valid JSON string -- JSON strings must be inside double quotes
Edit: took the failing example above, wrapped the utf-8 in doublequotes, and it decoded:
var_dump(json_decode('"\ud83c\udf83\ud83c\udf83\ud83c\udf83"'));
string(12) "🎃🎃🎃"
(I don't know what the glyphs should look like, I don't eve know if I have the right fonts installed, but the string decoded)

Related

How can i write a file in PHP with encode ISO-8859-1? [duplicate]

This question already has answers here:
Convert utf8-characters to iso-88591 and back in PHP
(10 answers)
Closed 6 years ago.
How can i write a file in PHP with encode ISO-8859-1?
Im using the function
$file = fopen("file.txt", "a");
When the file is created, it appears with encoding UTF-8 and i want it in ISO-8859-1.
UTF-8 supports all the characters found in ISO-8859-1... it's best to stick with UTF-8 as it supports the most amount of characters commonly used and will give you the least amount of problems.

Decode hex string to latin characters [duplicate]

This question already has answers here:
How to convert HTML entities like – to their character equivalents?
(5 answers)
Closed 7 years ago.
I have string:
tomas
there is decoded string tomas
I found that there is hec decode type : http://www.codetable.net/unicodecharacters
Does in PHP exists fuction to encode hex to latin characters ?
Those are not hex characters, but HTML entities.
PHP can decode them with html_entity_decode().

Convert Unicode escape sequence to UTF-8 [duplicate]

This question already has answers here:
Unicode character in PHP string
(8 answers)
Closed 2 years ago.
I'm trying to convert some characters with PHP before inserting to MySQL DB a JSON object with this kind of data:
\u00c9
that means: É
I tried this but it didn't work:
echo utf8_encode(print_r('\u00c9'));
I've read that it's in Unicode but i can't find the way to print it before inserting it. Any ideas?
Take a look at this answer. TL;DR:
echo json_decode('"\u00c9"');

PHP characters error [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
error when uploading string with special characters
I have a string say
$what = suggests ‘
i am not able to upload $what as it is, it throws decode error
I also tried using url_encode, url_decode, htmlspecialcharacters,utf8 etc.,but for no use.
url_encode, url_decode makes it as following:
suggests ?? but not as suggests ‘
What should i do for $what to be as
suggests ‘
Using Hixie’s decoder, it’s easy to check that ‘ is the UTF-8 encoded representation of U+2018 LEFT SINGLE QUOTATION MARK (‘) misinterpreted as separate bytes if were windows-1252 encoded. It’s more difficult to say why this happens—insufficient information about context and code.

Removing/Replacing ” from string [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to decode numeric HTML entities in PHP
How does one remove/replace ” characters from a string?
I've tried html_entity_decode but it don't seem to work. There are other similar characters in the string that don't seem to be converted or removed.
Any ideas?
The issue is that html_entity_decode() doesn't translate numeric entities.
I added an answer to the suggested duplicate How to decode numeric HTML entities in PHP
str_replace(array('”', '”'), '', $thestring);
Here is a working example: http://codepad.org/gXrZcxaF
Does this do what you're looking for:
http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php Converting smart quotes and other characters with PHP so they display correctly
http://ca2.php.net/manual/en/function.htmlentities.php#84612 Dealing with Numeric entities in PHP (comment on the manual)

Categories