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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度