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.
Related
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)
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I'm having an issue with getting the correct character encoding for data being POSTed which is built up from multiple sources (I get the data as a single POST variable). I think they're not in the same character encoding...
For instance, take the symbol £. If I do nothing to the character encoding I get two results:
a = £ and b = £
I've tried using various configurations of iconv() like so;
$data = iconv('UTF-8', 'windows-1252//TRANSLIT', $_POST['data']);
The above results in a = £ and b = �
I've also tried utf8_encode/decode as well as html_entity_decode, as I think there's a possibility that one of the pound symbols are being generated using html_entities.
I've tried setting the character encoding in the header which didn't work. I just can't get both instances to work at the same time.
I'm not sure what to try next, any ideas?
I've managed to work around this issue by finding the content that was causing an issue when everything else was in utf8 by using utf8_encode().
This appears to work for the £ symbol. I've not found any other characters causing an issue so far.
Note, I am still using iconv() in conjunction with this.
This question already has answers here:
Enclosing the string with double quotes
(3 answers)
Closed 8 years ago.
I am trying to build a function (unless there is already one, I was not able to find one) that satisfies:
being saved in a MySQL database → mysqli_real_escape_string
being saved in a serialized array in a MySQL database (I had issues when unserialize failed)
as for output:
doesn't interfer with HTML → utf8_encode(htmlentities($source, ENT_QUOTES | ENT_HTML401, 'UTF-8'));
doesn't interfer with it being a query in an URL, thus encoding the '&','%'
Please give me any advice if there is an idea on how to improve secure encoding.
And I am not sure about the functions give, whether they are the best to be used.
I also had issues with non-printable characters and tried
PHP: How to remove all non printable characters in a string?
$s = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\x9F]/u', '', $s);
EDIT
Because of the diversity of this question, I want to substantiate the question on how to clean a string that is an element of an array that is put with serialize() in a database ´?
For instance, I had a failure when trying to unserialize after having put a string containing a newline (\n or \r) into an string element of an array that has been serialized successfully...
EDIT_2
The reason for why I have tried to issue encoding HTML entities before saving them into the DB using mysqli_real_escape_string() is that when recalling/loading this object from the DB, the data has changed. For example a user wants to put the string test'test into the database that is encoded by mysqli_real_escape_string() to test\'test and then when loaded from the DB it's still test\'test whcih is NOT what the user wants to have neither what he has sent . Please if you could find a solution for this -- mine was to apply sth. like where mysqli_real_escape_string() had no effect as the quotes have already been HTML encoded.
From the top of my head, I feel you should try json_encode and json_decode
This question already has answers here:
PHP: Replace umlauts with closest 7-bit ASCII equivalent in an UTF-8 string
(7 answers)
Closed 9 years ago.
i am looking for a method or maybe a conversion table that knows how to convert Umlauts and special characters to their most likely representation in ascii.
Example:
Ärger = aerger
Bôhme = bohme
Søren = soeren
pjérà = pjera
Anyone any idea?
Update:
Apart from the good accepted Answer, i also found PECLs Normalizer to be quite interesting, though i can not use it due to the server not having it and not being changed for me.
Also do check out this Question if the Answers here do not help you enough.
I find iconv completely unreliable, and I dislike preg_match solutions and big arrays ... so my favorite way is ...
function toASCII( $str )
{
return strtr(utf8_decode($str),
utf8_decode('ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
}
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)