简体   繁体   中英

html entities for utf-8 character in php

I have used html_entities for UTF-8 in php.

$input = "<div> 'Testing' </div>";

echo htmlentities($input,ENT_NOQUOTES,"UTF-8");

But, above encoding is working for normal input, if i give below input and use encoding then I am getting blank output.

$input = "<div>Other 'user' is working on this line. Please contribute the next line.</div>";

echo htmlentities($input,ENT_NOQUOTES,"UTF-8");

I dont know how this is giving blank output. If i print $input then I am getting below value in $input.

<div>Other user working on this line.�Please contribute the next line.</div>

Is any thing missed in htmlentities code, Please folks provide your suggestions.

Thanks,

-Pravin.

Try passing $input to utf8_encode first, and then passing the data to htmlentities with only the ENT_NOQUOTES option set:

<?php

$input = "<div>Other 'user' is working on this line. Please contribute the next line.</div>";
echo htmlentities(utf8_encode($input),ENT_NOQUOTES);

?>

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