I am getting special characters from the textarea input on my form
So if I enter the below text
Philbrick, whose “In the Heart of the Sea: The Tragedy of the Whaleship Essex” recounted the real-life inspiration for Melville’s shipwreck, wears his erudition lightly.
I get the following when I access it in php.
Philbrick, whose “In the Heart of the Sea: The Tragedy of the Whaleship Essex†recounted the real-life inspiration for Melville’s shipwreck, wears his erudition lightly.
I tried the below before accessing the text , but replace is not working. Are these special characters not matching when I am copy pasting those in the code or its something else which is missing?
$string = htmlspecialchars($_POST["t"]) ;
$string = html_entity_decode($string, ENT_QUOTES, "UTF-8");
$string = str_replace('“', "\"", $string);
$string = str_replace('’', "'", $string);
There may not be anything wrong with what you're seeing. You may not need to mangle the $_POST with htmlentities corrections or otherwise. It could be that you're looking at a barebones browser output.
In case you're debugging this by spitting it out with something like print_r( $_POST ); die;
, make sure that somewhere above it in your page you have a meta line setting your character encoding to UTF-8:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
That will ensure that the smart characters (presumably pasted from somewhere) render properly on screen.
Completely unrelated: Excellent book, BTW. Love the beginning scene with gaunt sailors hoarding their piles of bones.
You actually have not an ordinary single and double quotes, but some fancy unicode version: “ ” ’
Try utf8_decode
. BTW what encoding do you use, Windows-1250
?