dtttlua7165 2014-02-02 21:39
浏览 117

双引号继续在PHP的shell_exec和sed中解析

I've spent hours trying to figure this out. I am using shell_exec (yes, I know the security problems associated with this) and sed to change text in a file.

The problem is no matter what I try I can't seem to output the text with the quotes still intact. I've tried almost every combination of single and double quotes I could to escape it, but it hasn't worked. After hours of trying, I decided to ask the question here.

The code is in a PHP file:

shell_exec('sed -i "s/patterntoreplace/yolo(word,"Hello Everyone", word)/" test.txt

The problem is that the file ends up with:

yolo(word,Hello Everyone, word)

The quotes keep getting parsed and I absolutely need them. I tried various things such as putting it into a variable, using escapeshellarg and escapeshellcmd and trying various combinations of single and double quotes, but I still can't get it to work.

This is very frustrating for me because this is the last part of my project and it should be simple, yet I can't run my program without the quotes. It's rather infuriating.

Can someone please tell me what to replace in that command to get quotes to output correctly?

  • 写回答

3条回答 默认 最新

  • dongzhimin2231 2014-02-02 21:54
    关注

    have you tried to use \' instead of ' and \" instead of " where you dont wnat them to be parsed? They said that already! :)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用