我有这样的文字:逃生HTML文本在ZF2
<p><strong>Lorem</strong> ipsur </p>
要看到不带HTML标签文本Zend框架2我该怎么办?
我试图把:
<?php echo $this->escapehtml($array['text']); ?>
我读的安全性并不好做:
<?php echo $array['descrizione']; ?>
我有这样的文字:逃生HTML文本在ZF2
<p><strong>Lorem</strong> ipsur </p>
要看到不带HTML标签文本Zend框架2我该怎么办?
我试图把:
<?php echo $this->escapehtml($array['text']); ?>
我读的安全性并不好做:
<?php echo $array['descrizione']; ?>
林不知道如果我理解这个问题,因为我不知道的内容你的数组。
basicaly如果你想花葶一个变量的内容,比方说,$input
,你必须调用,正如你所提到
$this>escapeHtml($input)
实际上,PhpRenderer包括一个选择,你可以使用这个帮手目的:EscapeHtml,EscapeHtmlAttr,EscapeJs,EscapeCss和EscapeUrl。
您可以了解这个here
另外,如果你想要更多的控制,你可以使用的Zend \逃避者,在两行代码让你escape html,这样
$escaper = new Zend\Escaper\Escaper('utf-8');
$output = $escaper->escapeHtml($input);
$escaper = new Zend\Escaper\Escaper('utf-8');
$output = $escaper->escapeHtmlAttr($input);
我建议你读了3个环节,他们都非常短,会给你一个更好的理解过程站在你正在做的事情上。
此时在escapeHtml中没有选项来允许某些标记。你有什么在这些特定情况下做的是改变返回值:
<?php
$str = $this->escapehtml($array['text']); ?>
$str = preg_replace(
array('#href="(.*)"#', '#<(/?(?:pre|a|b|br|em|u|ul|li|ol|p|strong)(\shref=".*")?/?)>#'),
array('href="\1"', '<\1>'),
$str
);
echo $str;
您可以添加/从部分pre|a|b|br|em|u|ul|li|ol|p|strong
您的需要移除标签。此外,这段代码只允许使用href的锚标签。