duanjiwei1283 2011-11-03 18:41
浏览 70
已采纳

PHP - 在文本框中删除PHP内容?

Hey guy's i'm making a website which involves submiting an ad for a gameserver. I'm wondering if it is possible to strip PHP related tags from the content of the textbox? As if I leave it how it is now, It may become a security risk later on. Currently the only thing I am doing to the content is nl2br(). What is the best way to do this?

Thanks.

  • 写回答

5条回答 默认 最新

  • dpxnrx11199 2011-11-03 18:53
    关注
    1. Why do you care about php code in textbox, can it be executed in any way?
    2. I suppose that you want to leave html tags but remove just php code (in other case you could just use strip_tags function or htmlspecialchars).

    So, the solution:

    <?php
    //here is content from the textarea (filled it for example)
    $content = 'some <?php echo "test"; ?> <?=test?> content <br/> here';
    
    $content = preg_replace('/<\?((?!\?>).)*\?>/s', '', $content); //strip all the php code
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献