Decode hex string to latin characters [duplicate] - php

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().

Related

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

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)

detecting chinese characters in php string [duplicate]

This question already has answers here:
Php - regular expression to check if the string has chinese chars
(4 answers)
Closed 8 years ago.
I am trying to detect chinese characters in a string I have in PHP, currently I am trying to do this:
$bio = '全部都好有用架 無用的我都一早打入冷宮唔見哂(… 有意/想睇圖都歡迎留whatsapp or line: chibimasakishop 可綠線/將軍澳線交收';
if (preg_match('/[\x{4e00}-\x{9fa5}]+.*\-/u', $bio) === 1) {
var_dump('contains a chinese character');
}
why isn't this working?
Try this
if(preg_match("/\p{Han}+/u", $bio))
{
var_dump('contains a chinese character');
}
Reference : Php check if the string has Chinese chars
in your case i think you have "\-" extra, i think
/[\x{4e00}-\x{9fa5}]+.*/u
should work

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"');

convert encoding in php doesn't convert between ASCII and UTF-8 [duplicate]

This question already has answers here:
Convert ASCII TO UTF-8 Encoding
(5 answers)
Closed 6 years ago.
is UTF-8 not the same as ASCII? how you would explain the different results i get from:
$result = mb_detect_encoding($PLAINText, mb_detect_order(), true);
Sometimes i get "UTF-8" in $result and sometimes i get "ASCII". so they are different, but that is not my question, my question is why iconv() code doesn't convert from ASCII to UTF-8?
$result = iconv("ASCII","UTF-8//IGNORE",$PLAINText);
i check the $result encoding later using the mb_detect_encoding() function and it is still "ASCII" , not "UTF-8".
The reason is that when using only ASCII characters in an UTF-8 string, the UTF-8 string is indistinguishable from an ASCII string. (Unless a byte order mark is used, but it's optional.)

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