简体   繁体   中英

PHP Double Quotes from MySQL, breaking htmlentities

I am having an issue with my results here. Please someone can tell what I'm doing wrong.

I have this text inside a mysql field:

----------------------------------------------------
text “strange double quotes” "normal double quotes"
----------------------------------------------------

Inside a textarea I echo the string fron the database

<textarea>
    $string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
    echo htmlspecialchars($string);
</textarea>

And crashes (does not display anything).


but if I only have normal text or normal quotes:

"this is a correct text with quotes"

This works.

Do you know what I need to do?

TY

The code you have works as expected:

<?php
$string = 'text “strange double quotes” "normal double quotes"';

$string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
echo htmlspecialchars($string);
?>

Yields:

text “strange double quotes” &quot;normal double quotes&quot;

Check the value of $string before passing it into htmlspecialchars_decode , eg:

<?php
$string = null;

$string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
echo htmlspecialchars($string);
?>

Yields nothing/empty/blank, per your error description.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM