简体   繁体   English

在HTML实体中使用href

[英]use a href inside html entities

I use html entities to secure my site. 我使用html entities来保护我的网站。
And my client want to add link in his post using the CMS. 我的客户想使用CMS在他的帖子中添加链接。
how to make exception in html entities? 如何在HTML实体中设置例外?

my code example: 我的代码示例:

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

My code display this message: 我的代码显示此消息:

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

If my question is not clear please ask. 如果我的问题不清楚,请询问。
Really appreciate. 万分感激。

I believe what you want to do is pass into the DB with htmlentities() so it doesn't mess with your DB. 我相信您想要做的是通过htmlentities()传递给数据库,这样就不会与您的数据库混淆。 To retrieve them you would use html_entity_decode(). 要检索它们,您可以使用html_entity_decode()。 The html_entity_decode() converts all strings with HTML entities back to there original string. html_entity_decode()将带有HTML实体的所有字符串转换回原始字符串。

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

Hopefully this answers your question. 希望这能回答您的问题。

Edit: Raw data retrieved: http://www.example.com 编辑:检索原始数据: http://www.example.com : http://www.example.com

Through htmlentities it spits out the HTML entities, which the browser cannot interpret when attempting to find that page. 通过htmlentities,它吐出了HTML实体,浏览器在尝试找到该页面时无法解释该HTML实体。 The use of htmlentities() (please if I'm wrong correct me) is to encode user input before passing it anywhere else. htmlentities()的使用(如果我错了,请纠正我)是在将用户输入传递到其他任何地方之前对其进行编码。

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

Passed though htmlentities: 通过htmlentities传递:

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

(This way it can't mess with anything in your database, better example is the use of PHP/MySQL but I'm not well versed to give that exact example at the moment.) (这样一来,它就不会与数据库中的任何内容发生混乱,更好的例子是使用PHP / MySQL,但目前我并不精通给出确切的例子。)

However this would expose your site when decoding it as well and other precautions would have to be taken. 但是,这也会在解码站点时暴露您的站点,因此必须采取其他预防措施。

Try this : 尝试这个 :

<?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