dongqiulei6805 2012-12-19 03:16
浏览 51
已采纳

用PHP解释字符串的类型[重复]

Possible Duplicate:
Difference between single quote and double quote string in php

I'm a newbie to PHP and I'm getting a little confused about how to specify strings.

There seem to be 4 ways to specify strings

  1. Single quoted strings
  2. Double quote strings
  3. Heredoc
  4. Nowdoc (since PHP 5.3.0)

I was wondering why there are so many types of specifications and what is the best way to specify a string?

Because again in this article it says single and double quotes are equally fast but there are others which disagree.

Why even have single and double quotes? Does it add speed, accuracy is any one better under certain conditions?

  • 写回答

3条回答 默认 最新

  • doutui9606 2012-12-19 03:19
    关注

    Single-quoted strings pay attention to less escape sequences than double-quoted strings. Compare:

    echo "one
    two";
    # one
    # two
    

    with:

    echo 'one
    two';
    # one
    two
    

    The other key difference is that double-quoted strings interpolate variables. Single-quoted strings don't.

    As for heredoc and nowdoc, they're just ways to specify long strings (that may contain quotes - and if they do, you don't have to escape them) in a bit of a nicer way. Why are there two? Well, heredoc is to double-quoted strings as nowdoc is to single-quoted strings.

    (All this information and more is available in the PHP documentation, by the way.)

    So, there are a lot of different types of string literal because there are a lot of different uses for string literals.

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

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失