duanshan1511 2014-06-26 18:42
浏览 84
已采纳

使用str_replace替换img src无效

Hi I'm trying to modify the src of a image that I uploaded by ckfinder and I want a full path I see other answers here but I dont know why my code doesn't work ,look at it please

$html = '<p> <img alt="" src="/deconsultas/javascript/ckfinder/files/images/xxx.jpg"/></p>';
$dato = str_replace("src=&quot/deconsultas/javascript","a",$html);
echo $dato;

Where is the error please ?

  • 写回答

3条回答 默认 最新

  • doumei2023 2014-06-26 18:48
    关注

    I think you need this.

    $html = '<p> <img alt="" src="/deconsultas/javascript/ckfinder/files/images/xxx.jpg"/></p>';
    $dato = preg_replace("/\/deconsultas\/javascript/","a",$html);
    echo $dato;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dongmeiba6151 2014-06-26 18:49
    关注

    just change str_replace("src=&quot/deconsultas/javascript","a",$html) to str_replace("src=\"/deconsultas/javascript","a",$html)

    评论
  • dowdw44426 2014-06-26 18:54
    关注

    Escape quote with slash

    use

    \"

    instead of

    &quot

    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求制作一个个人网页,
  • ¥15 寻涂色内存脚本作者有项目有市场有资源.却技术
  • ¥15 蓝桥杯c51单片机问题
  • ¥15 ajax跨域问题请求修改代码
  • ¥15 python matplotlib
  • ¥15 短信测压+语音,有偿,必须用Python
  • ¥20 COCOS2DX的protobuf协议注册函数问题
  • ¥15 (标签-Pytorch|关键词-Stream)
  • ¥15 求深圳2019年开放数据应用创新大赛的营运车辆数据!
  • ¥15 软件UI界面绘制折线图