繁体   English   中英

在HTML实体中使用href

[英]use a href inside html entities

我使用html entities来保护我的网站。
我的客户想使用CMS在他的帖子中添加链接。
如何在HTML实体中设置例外?

我的代码示例:

<p><?php echo h($row['message']) ?></p>
//h is my function for htmlentities

我的代码显示此消息:

"You can click this link <a href="###">Link</a>"
//And I dont know my data insert '\'
//It become <a href=\"###\">Link</a>

如果我的问题不清楚,请询问。
万分感激。

我相信您想要做的是通过htmlentities()传递给数据库,这样就不会与您的数据库混淆。 要检索它们,您可以使用html_entity_decode()。 html_entity_decode()将带有HTML实体的所有字符串转换回原始字符串。

http://php.net/manual/zh/function.html-entity-decode.php

希望这能回答您的问题。

编辑:检索原始数据: http://www.example.com : http://www.example.com

通过htmlentities,它吐出了HTML实体,浏览器在尝试找到该页面时无法解释该HTML实体。 htmlentities()的使用(如果我错了,请纠正我)是在将用户输入传递到其他任何地方之前对其进行编码。

用户输入: <script>hacks</script>

通过htmlentities传递:

&ltscript&gthacks&lt (whatever backslash is)script&gt

(这样一来,它就不会与数据库中的任何内容发生混乱,更好的例子是使用PHP / MySQL,但目前我并不精通给出确切的例子。)

但是,这也会在解码站点时暴露您的站点,因此必须采取其他预防措施。

尝试这个 :

<?php 
   $link = h(stripslashes($row['message'])); 
?>


You can click this link <a href='<?php echo $link; ?>'>Link</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM