dsxsou8465 2014-02-17 01:02
浏览 31
已采纳

这是在PHP中转义引号的正确方法吗?

I'm writing a laravel controller if that is relevant here.

"\"$alias\""

Here I am passing the variable in alias, and I want to surround it with double quotes.

"\"remote\""

Here I am just trying to pass the word remote enclosed in double quotes.

Not sure if I am doing this correctly, or if there is a better way to do it.

For the ones without variables, is '"remote"' a better way to achieve what I want?

Thanks again!

  • 写回答

2条回答 默认 最新

  • douliao8318 2014-02-17 01:04
    关注
    echo "The value is \"$value\"";
    

    and

    echo 'The value is "'.$value.'"';
    

    are both perfectly valid to show a variable in double quotes.


    echo "The word is \"bird\"";
    

    and

    echo 'The word is "bird"';
    

    are both perfectly valid to show a constant phrase in double quotes.


    Remember that variables aren't parsed inside single-quoted strings, so echo 'The value is $value'; won't work.

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

报告相同问题?

悬赏问题

  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题