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?
php
add a comment |
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?
php
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 usingmysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
– millimoose
Jan 14 '12 at 18:08
add a comment |
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?
php
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
php
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 usingmysql_real_escape_string, and using the same encoding (preferrably UTF-8) end to end.
– millimoose
Jan 14 '12 at 18:08
add a comment |
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 usingmysql_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
add a comment |
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.
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. Addechobefore 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
|
show 2 more comments
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.
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. Addechobefore 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
|
show 2 more comments
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.
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. Addechobefore 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
|
show 2 more comments
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.
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.
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. Addechobefore 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
|
show 2 more comments
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. Addechobefore 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
|
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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