How to display/echo html as text in php with utf-8 text in it?
I'm trying to display/echo html code text as it is in php. I tried htmlentitied() function but it converts the whole text to html entities.
In my problematic situation, I have the following html text:
$html='
<table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> <tbody><tr> <td>
this is td</td></tr></tbody></table><br/>
The quick brown fox jumps over the lazy dog
<div>敏捷的棕色狐狸跃过懒狗</div><br>
<div>怠惰な犬以上の速い茶色のキツネジャンプ</div><br>
<div>게으른 개를 통해 빠른 갈색 여우 점프</div><br>
<div>ಸೋಮಾರಿಯಾಗಿ ನಾಯಿಗಳು ಮೇಲೆ ಶೀಘ್ರ ಕಂದು ನರಿ ಜಂಪ್</div><br>
<div>게으른 개를 통해 빠른 갈색 여우 점프</div><br>
<div>דער גיך ברוין פוקס שפּרינגען איבער די פויל הינט</div><br>
<div>आलसी कुत्तों पर जल्दी भूर开发者_运维百科े रंग लोमड़ी कूद</div><br>
<div>ويقفز الثعلب البني السريع فوق الكلب الكسول</div><br>
<div>La cigüeña tocaba el saxofón sobre el perro perezoso</div><br>
<div>দ্রুত বাদামী অলস কুকুরের উপর শিয়াল লাফ</div><br>
<div>השועל החום הזריז לקפוץ מעל כלבים עצלן</div><br>
';
echo htmlentities($html);
The above code gives me lots of garbage text in output. Is there any way I can have that utf-8 as it is? I'm looking for something really powerful like the "code sample" function in stackoverflow editor.
You can also add in the very beginning of your file the line:
<?php header('Content-type: text/html; charset=utf-8');?>
Specify the charset as UTF-8:
echo htmlentities($html, ENT_COMPAT, 'UTF-8');
精彩评论