How can I convert this (′) character to html entities using php?









up vote
0
down vote

favorite












I want to make this character (′) html entity for storing in my database using php. I am using MySQL databse. I use:



$string = "HTML5′s placeholder Attribute";
$newStr = htmlspecialchars($string, ENT_QUOTES);
echo $newStr;


the above code prints the following



HTML5â?²s placeholder Attribute 


How can I make this (′) character an HTML entity?










share|improve this question



















  • 1




    That character's not a special character in HTML, you shouldn't escape it as such. Use your database driver's string escaping functions, or better yet a database API that gives you parameter interpolation. (Not knowing what database you're using and what libraries are available in your PHP install, it's not really possible to make a less vague answer.)
    – millimoose
    Jan 14 '12 at 17:53











  • @Inerdial I am using MySQL database
    – Rizwan Khan
    Jan 14 '12 at 17:59






  • 1




    Then the simplest solution is using mysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
    – millimoose
    Jan 14 '12 at 18:08














up vote
0
down vote

favorite












I want to make this character (′) html entity for storing in my database using php. I am using MySQL databse. I use:



$string = "HTML5′s placeholder Attribute";
$newStr = htmlspecialchars($string, ENT_QUOTES);
echo $newStr;


the above code prints the following



HTML5â?²s placeholder Attribute 


How can I make this (′) character an HTML entity?










share|improve this question



















  • 1




    That character's not a special character in HTML, you shouldn't escape it as such. Use your database driver's string escaping functions, or better yet a database API that gives you parameter interpolation. (Not knowing what database you're using and what libraries are available in your PHP install, it's not really possible to make a less vague answer.)
    – millimoose
    Jan 14 '12 at 17:53











  • @Inerdial I am using MySQL database
    – Rizwan Khan
    Jan 14 '12 at 17:59






  • 1




    Then the simplest solution is using mysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
    – millimoose
    Jan 14 '12 at 18:08












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to make this character (′) html entity for storing in my database using php. I am using MySQL databse. I use:



$string = "HTML5′s placeholder Attribute";
$newStr = htmlspecialchars($string, ENT_QUOTES);
echo $newStr;


the above code prints the following



HTML5â?²s placeholder Attribute 


How can I make this (′) character an HTML entity?










share|improve this question















I want to make this character (′) html entity for storing in my database using php. I am using MySQL databse. I use:



$string = "HTML5′s placeholder Attribute";
$newStr = htmlspecialchars($string, ENT_QUOTES);
echo $newStr;


the above code prints the following



HTML5â?²s placeholder Attribute 


How can I make this (′) character an HTML entity?







php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 15:07









Cœur

16.9k9102139




16.9k9102139










asked Jan 14 '12 at 17:51









Rizwan Khan

140716




140716







  • 1




    That character's not a special character in HTML, you shouldn't escape it as such. Use your database driver's string escaping functions, or better yet a database API that gives you parameter interpolation. (Not knowing what database you're using and what libraries are available in your PHP install, it's not really possible to make a less vague answer.)
    – millimoose
    Jan 14 '12 at 17:53











  • @Inerdial I am using MySQL database
    – Rizwan Khan
    Jan 14 '12 at 17:59






  • 1




    Then the simplest solution is using mysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
    – millimoose
    Jan 14 '12 at 18:08












  • 1




    That character's not a special character in HTML, you shouldn't escape it as such. Use your database driver's string escaping functions, or better yet a database API that gives you parameter interpolation. (Not knowing what database you're using and what libraries are available in your PHP install, it's not really possible to make a less vague answer.)
    – millimoose
    Jan 14 '12 at 17:53











  • @Inerdial I am using MySQL database
    – Rizwan Khan
    Jan 14 '12 at 17:59






  • 1




    Then the simplest solution is using mysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
    – millimoose
    Jan 14 '12 at 18:08







1




1




That character's not a special character in HTML, you shouldn't escape it as such. Use your database driver's string escaping functions, or better yet a database API that gives you parameter interpolation. (Not knowing what database you're using and what libraries are available in your PHP install, it's not really possible to make a less vague answer.)
– millimoose
Jan 14 '12 at 17:53





That character's not a special character in HTML, you shouldn't escape it as such. Use your database driver's string escaping functions, or better yet a database API that gives you parameter interpolation. (Not knowing what database you're using and what libraries are available in your PHP install, it's not really possible to make a less vague answer.)
– millimoose
Jan 14 '12 at 17:53













@Inerdial I am using MySQL database
– Rizwan Khan
Jan 14 '12 at 17:59




@Inerdial I am using MySQL database
– Rizwan Khan
Jan 14 '12 at 17:59




1




1




Then the simplest solution is using mysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
– millimoose
Jan 14 '12 at 18:08




Then the simplest solution is using mysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
– millimoose
Jan 14 '12 at 18:08












1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










You need to use htmlentities() here, as that specific quote thingy does not need escaping normally. And you also need to specifiy the charset, as you otherwise get those Latin-1 equivalent escapes:



echo htmlentities("′", ENT_QUOTES, "UTF-8");


Should either get you or ′ as result.






share|improve this answer






















  • How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
    – Rizwan Khan
    Jan 14 '12 at 18:00










  • You use your string as first parameter, like in your original example.
    – mario
    Jan 14 '12 at 18:01










  • I use my string as first parameter. it prints nothing.
    – Rizwan Khan
    Jan 14 '12 at 18:07










  • No, it's not an output function. Add echo before it.
    – mario
    Jan 14 '12 at 18:08










  • that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
    – Rizwan Khan
    Jan 14 '12 at 18:17










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8864127%2fhow-can-i-convert-this-character-to-html-entities-using-php%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










You need to use htmlentities() here, as that specific quote thingy does not need escaping normally. And you also need to specifiy the charset, as you otherwise get those Latin-1 equivalent escapes:



echo htmlentities("′", ENT_QUOTES, "UTF-8");


Should either get you or ′ as result.






share|improve this answer






















  • How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
    – Rizwan Khan
    Jan 14 '12 at 18:00










  • You use your string as first parameter, like in your original example.
    – mario
    Jan 14 '12 at 18:01










  • I use my string as first parameter. it prints nothing.
    – Rizwan Khan
    Jan 14 '12 at 18:07










  • No, it's not an output function. Add echo before it.
    – mario
    Jan 14 '12 at 18:08










  • that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
    – Rizwan Khan
    Jan 14 '12 at 18:17














up vote
4
down vote



accepted










You need to use htmlentities() here, as that specific quote thingy does not need escaping normally. And you also need to specifiy the charset, as you otherwise get those Latin-1 equivalent escapes:



echo htmlentities("′", ENT_QUOTES, "UTF-8");


Should either get you or ′ as result.






share|improve this answer






















  • How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
    – Rizwan Khan
    Jan 14 '12 at 18:00










  • You use your string as first parameter, like in your original example.
    – mario
    Jan 14 '12 at 18:01










  • I use my string as first parameter. it prints nothing.
    – Rizwan Khan
    Jan 14 '12 at 18:07










  • No, it's not an output function. Add echo before it.
    – mario
    Jan 14 '12 at 18:08










  • that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
    – Rizwan Khan
    Jan 14 '12 at 18:17












up vote
4
down vote



accepted







up vote
4
down vote



accepted






You need to use htmlentities() here, as that specific quote thingy does not need escaping normally. And you also need to specifiy the charset, as you otherwise get those Latin-1 equivalent escapes:



echo htmlentities("′", ENT_QUOTES, "UTF-8");


Should either get you or ′ as result.






share|improve this answer














You need to use htmlentities() here, as that specific quote thingy does not need escaping normally. And you also need to specifiy the charset, as you otherwise get those Latin-1 equivalent escapes:



echo htmlentities("′", ENT_QUOTES, "UTF-8");


Should either get you or ′ as result.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 14 '12 at 18:03

























answered Jan 14 '12 at 17:56









mario

123k17178253




123k17178253











  • How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
    – Rizwan Khan
    Jan 14 '12 at 18:00










  • You use your string as first parameter, like in your original example.
    – mario
    Jan 14 '12 at 18:01










  • I use my string as first parameter. it prints nothing.
    – Rizwan Khan
    Jan 14 '12 at 18:07










  • No, it's not an output function. Add echo before it.
    – mario
    Jan 14 '12 at 18:08










  • that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
    – Rizwan Khan
    Jan 14 '12 at 18:17
















  • How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
    – Rizwan Khan
    Jan 14 '12 at 18:00










  • You use your string as first parameter, like in your original example.
    – mario
    Jan 14 '12 at 18:01










  • I use my string as first parameter. it prints nothing.
    – Rizwan Khan
    Jan 14 '12 at 18:07










  • No, it's not an output function. Add echo before it.
    – mario
    Jan 14 '12 at 18:08










  • that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
    – Rizwan Khan
    Jan 14 '12 at 18:17















How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
– Rizwan Khan
Jan 14 '12 at 18:00




How i can convert this from a string, like this string "HTML5′s placeholder Attribute".
– Rizwan Khan
Jan 14 '12 at 18:00












You use your string as first parameter, like in your original example.
– mario
Jan 14 '12 at 18:01




You use your string as first parameter, like in your original example.
– mario
Jan 14 '12 at 18:01












I use my string as first parameter. it prints nothing.
– Rizwan Khan
Jan 14 '12 at 18:07




I use my string as first parameter. it prints nothing.
– Rizwan Khan
Jan 14 '12 at 18:07












No, it's not an output function. Add echo before it.
– mario
Jan 14 '12 at 18:08




No, it's not an output function. Add echo before it.
– mario
Jan 14 '12 at 18:08












that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
– Rizwan Khan
Jan 14 '12 at 18:17




that's code working fine echo htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . But when i store my string to db $str = htmlentities("HTML5′s placeholder Attribute", ENT_QUOTES, "UTF-8"); . It stores an empty value
– Rizwan Khan
Jan 14 '12 at 18:17

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8864127%2fhow-can-i-convert-this-character-to-html-entities-using-php%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown