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)
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:
PHP URL Encoding / Decoding
(4 answers)
Closed 8 years ago.
I can print a url with the following:
<?php print $base_url . $node_url ?>
What is the standard PHP way of converting special characters?
So instead of: http://time.com/3525666/ebola-psychology-fear-symptoms/
I need http%3A%2F%2Ftime.com%2F3525666%2Febola-psychology-fear-symptoms%2F
You would use urlencode for that sort of escaping.
Other escaping functions exist for other purposes, like htmlspecialchars for making text output safely for HTML display.
use his function in php , it is built in function to encode in url format
urlencode();
Just to add, htmlspecialchars, as mentioned above in the comment can take care of few html entities, not all of them.
Use htmlentities() instead:
$query_string = 'foo=' .urlencode($foo) . '&bar=' . urlencode($bar);echo '';
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"');
This question already has answers here:
htmlentities() vs. htmlspecialchars()
(12 answers)
Closed 8 years ago.
I have read their documentation, but I still don't get when to use each of them and their difference.
Let's consider the situation of having a general string in a variable and needing to echo it inside HTML code. If it has any HTML markup in it, I want it converted to HTML code (< replaced by <, & replaced by &. If it has UTF special chars that aren't available in HTML code, it's replaced by HTML number (• replaced by •).
What's the best function for that?
A harder need: unprintable chars, like \n, char(10), char(13), etc, be replaced by their number code, in the case the string is printed inside <pre> or any special textarea so that the string be dumped.
htmlentities is a workaround for not having set the character type of the document properly. htmlspecialchars is the correct function to use for merely writing text into an HTML document.
As to your second question, I think you're looking for addcslashes.
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.