htmlentities使字符串变空

时间:2013-10-15 01:31:52

标签: php html-entities

我正在运行这段代码:

var_dump($this->string);
$this->string = htmlentities($this->string, ENT_COMPAT, "UTF-8", false);
var_dump($this->string);

它在第一个var_dump()输出字符串,但在第二个var_dump()中为空。为什么要这样做?

string(1787) "##Welcome newcomer

We have a `great place` here for you to write whatever you wish, and share it with your friends, family and other random people. Hopefully you enjoy writing for us, we can't wait to see what you have to write about and share with the community! 

##Markdown

We don't use your average editor, we use a much simpler one to write fast HTML code. It is called **Markdown**. Here we will show some basic and common Markdown syntax.

|||OTABLE|||
|||OTR|||
|||OTH|||Example|||CTH|||
|||OTH|||Syntax|||CTH|||
|||OTH|||Description|||CTH|||
|||CTR|||
|||OTR|||
|||OTD|||**Bold**|||CTD|||
|||OTD||||||AST||||||AST|||Bold|||AST||||||AST|||  
|||UND||||||UND|||Bold|||UND||||||UND||||||CTD|||
|||OTD|||Makes text thicker.|||CTD|||
|||CTR|||
|||OTR|||
|||OTD|||_Italic_|||CTD|||
|||OTD||||||AST|||Italic|||AST|||  
|||UND|||Italic|||UND||||||CTD|||
|||OTD|||Makes text slanted|||CTD|||
|||CTR|||
|||OTR|||
|||OTD|||[Google](http://google.com)|||CTD|||
|||OTD||||||LBR|||Google|||RBR||||||LPR|||http://google.com) |||CTD|||
|||OTD|||Makes a text link to a webpage|||CTD|||
|||CTR|||
|||OTR|||
|||OTD|||
|||OBLQU|||I am  
part of  
a quote  
|||CBLQU||||||CTD|||
|||OTD|||
|||GTR|||I am  
|||GTR|||part of  
|||GTR|||a quote  
|||CTD|||
|||OTD|||Creates a quote area|||CTD|||
|||CTR|||
|||OTR|||
|||OTD|||
    <html>
        <head>
            <title>I Am The Title</title>
        </head>
    </html>
|||CTD|||
|||OTD|||
    <html>|||BR|||
        <head>|||BR|||
            <title>I Am The Title</title>|||BR|||
        </head>|||BR|||
    </html>
|||CTD|||
|||OTD|||Creates a block of code|||CTD|||
|||CTR|||
|||OTR|||
|||OTD|||I am `inline code`|||CTD|||
|||OTD|||I am |||TIK|||inline code|||TIK||||||CTD|||
|||OTD|||Creates an inline code block|||CTD|||
|||CTR|||
|||CTABLE|||"
string(0) ""

2 个答案:

答案 0 :(得分:0)

尝试在第三个参数中将"UTF-8"更改为"iso-8859-1"。这是一个众所周知的... feature introduced in PHP 5.4。我想它可以完成这项工作。

上帝该死的PHP及其开发者。

答案 1 :(得分:-2)

htmlentities(string, quotestyle, character-set)

只有三个参数