dongtui2029 2018-09-21 13:27 采纳率: 0%
浏览 32
已采纳

Wordpress“esc ..”函数是否有任何反转功能?

I'm using the standart "esc_html" in Wordpress for insert data (textarea) to the db.

All works nice but how can I reverse the text?

For example:

I insert the text - You ready?! Let's go!

And in the db it's as I expected save it as - You ready?! Let's go!

Later, when I tried to display this text in my tooltip it's also display the text as You ready?! Let's go!

Please, I would like to know if there is any reverse for this function since I tried to use htmlspecialchars_decode() and realized it's not the same function.

Thanks!

  • 写回答

3条回答 默认 最新

  • duanhan7001 2018-09-21 14:46
    关注

    The answer is: generally speaking, you don't escape data when saving it to the database. You sanitize it. (And so you don't really need to worry about "reverting" the content from esc_* functions).

    You sanitize the input data when you're about to insert it into the database to prevent SQL injection attacks. If you're using the insert() method from the $wpdb object or the wp_insert_post() function to create a new post/page, then the sanizitation is done for you automatically.

    If you're writing a custom query (eg. $wpdb->query( "INSERT INTO table VALUES('a string', 'another string', '2018-09-21 10:35:52')" );) then you need to use the prepare() method to sanitize the query before running it (eg. $wpdb->query( $wpdb->prepare( "INSERT INTO table VALUES(%s, %s, %s)", array($string1, $string2, $date_string) ) );).

    When you're about to display the data on screen use any of the different esc_* functions to make sure nothing malicious is being printed on screen (like <script>alert('Hello!');</script>).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示