简体   繁体   中英

PHP htmlentities Not Working

I am retrieving text and HTML tags from a database while using this function to encode the values for the browser.

foreach ($row as $key => &$value){
    $value = htmlspecialchars_decode(
                 htmlentities($value,ENT_QUOTES), 
                 ENT_NOQUOTES
             );
}

Basically, I am looping through each row and converting quotes, single quotes, and other special characters to entities while keeping HTML tags.

However, when there's tags like <a href="example.com"> , the quotes are duplicated twice and outputs to this:

<a href=""example.com""> .

What am I doing wrong?

您应该使用htmlentities: htmlentities($str, ENT_QUOTES);

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