dongtanghuan1885 2011-04-21 22:05
浏览 17
已采纳

PHP撇号逃脱了破坏链接

I was provided with a set of data that represents URL links. Such as: "doug'sfood.jpg".

.

I keep these strings in an array, and then select them randomly to display inserting them into an

<img src="doug'sfood.jpg"></img>

What Chrome is putting out is:

<img src="doug&#39;sfood.jpg"></img>

I tried replacing the quotes with a php escaped (\') apostrophe, but this just ended the quote prematurely.

Can someone help me? Thanks.

  • 写回答

2条回答 默认 最新

  • dongxunhua2054 2011-04-21 22:14
    关注

    I think Chrome automatically escapes characters that are not correctly escaped.

    Always use:

    <img src="quote&#39;quote.jpg" alt="" />
    

    Instead of:

    <img src="quote'quote.jpg" alt="" />
    

    Certain characters should always be escaped in HTML, for example:

    ' -> &#39;
    & -> &#38; or &amp;
    

    Check the htmlspecialchars() and urlencode() functions, example:

    $string = "quote'quote.jpg";
    
    echo htmlspecialchars($string, ENT_QUOTES);
    // quote&#039;quote.jpg
    
    echo urlencode($string);
    // quote%27quote.jpg
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 hexo+github部署博客
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?