dongzhan1878 2013-03-29 18:55
浏览 17
已采纳

斜杠和''[关闭]之间的差异

Sorry if there is a question that's very similar to this or if there is answer somewhere else but I have a question that's been on my mind lately.

Most people that are versed in programming languages and strings would know that you can escape quotations with a slash (\")

Ex: echo "<input name=\"submit\" type=\"submit\" id=\"brandid\" value=\"submit\" /> ";

But what I usually do is use ' inside of " instead of slashes. So the code above would look something like this:

echo "<input name='submit' type='submit' id='brandid' value='submit' />
";

Could someone explain the differences between the two and the advantages or disadvantages between the two? Sorry if I didn't use the correct terminology or am missing something.

Thanks for any help in advance.

  • 写回答

2条回答 默认 最新

  • dtcuv8044 2013-03-29 19:06
    关注

    Depends on what you like, and what you need to do. If I've got a lot of variable substitution I need to do, double quotes and curly braces (if needed) are the way to go. I personally don't like adding extra unnecessary markup (read: escaping) if I don't need to.

    echo "Hello \"$username\", your last visit was on $lastVisit at $time";
    

    As opposed to...

    echo 'Hello "'.$username.'", your last visit was on '.$lastVisit.' at '.$time;
    

    If it's simple HTML markup and no variable substitution is required, then single quotes are fine.

    echo '<a href="index.php">Home</a>';
    

    No right answer here.

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

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入