Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htmlspecialcharacters\u decode/html\u entities\u decode-结果未解释为html_Php_Php 5.3 - Fatal编程技术网

Php htmlspecialcharacters\u decode/html\u entities\u decode-结果未解释为html

Php htmlspecialcharacters\u decode/html\u entities\u decode-结果未解释为html,php,php-5.3,Php,Php 5.3,正如标题所示,我遇到了一个迭代一系列已解码html的情况(尝试使用htmlspecialcharacters_decode()和html_entities_decode)。但是,DOM将解码的字符串视为textNode。php 5.3.28 样本: <div> <h1>This is in the middle of a template file</h1> <?php foreach ($as

正如标题所示,我遇到了一个迭代一系列已解码html的情况(尝试使用htmlspecialcharacters_decode()和html_entities_decode)。但是,DOM将解码的字符串视为textNode。php 5.3.28

样本:

    <div>
      <h1>This is in the middle of a template file</h1>
        <?php
            foreach ($assocArrayObjEle as $obyKey => $obyMeat) {
                 if (!is_null($obyMeat->description) &&  strlen($obyMeat->description)> 0)
                 {
                 print html_entity_decode($obyMeat->description);
                 }  
                }
        ?>
    </div>

这是在模板文件的中间。
结果如下:

这是在一个模板文件的中间(p>),这是HTML,括号不是作为实体序列而逃脱的,但是这个文本正文被视为HTML文本节点。这似乎不是我所找到的手册条目和阅读主题的预期结果。所有实体都得到了正确的处理,但结果只是作为DOM中的textNode而不是DOM元素重新处理。提前谢谢


正如示例输出所述,实体确实被重新分解为有效的标记,但它们被附加到DOM(或者更确切地说,是DOM决定的?)中,即这是包含元素的textNode的值,而不是DomeElement集。提前感谢

好的,因此无论出于何种原因,一次htmlspecialchars_decode()未完成。这非常奇怪,因为
否则需要显示为
&;lt这是必须的-不管怎样,如果其他人需要它,就把它留在这里。解决方案如下所示:

<div>
      <h1>This is in the middle of a template file</h1>
        <?php
            foreach ($assocArrayObjEle as $obyKey => $obyMeat) {
                 if (!is_null($obyMeat->description) &&  strlen($obyMeat->description)> 0)
                 {
                     echo htmlspecialchars_decode(htmlspecialchars_decode($obyMeat->description,  ENT_QUOTES), ENT_NOQUOTES); //2nd pass was necessary even tho there were no double escaped entites (amperstands not being double escaped).
                 }  
                }
        ?>
    </div>

这是在模板文件的中间。