我应该对单引号使用 php 引号转义还是在数组中使用双引号?
我意识到 php 数组中的单引号可能会出现问题:
<?php
$lang = array(
'tagline' => 'Let's start your project',
"h1" => "About Me"
);
?>
所以我将其更改为双引号:
<?php
$lang = array(
"tagline" => "Let's start your project",
"h1" => "About Me"
);
?>
我应该使用“php quote escapes”,而不是我刚才所做的吗? (顺便问一下“php quote escapes”怎么写?)
I realized that I can have problems with single quotes in php arrays:
<?php
$lang = array(
'tagline' => 'Let's start your project',
"h1" => "About Me"
);
?>
So I changed it to double quotes:
<?php
$lang = array(
"tagline" => "Let's start your project",
"h1" => "About Me"
);
?>
Should I use "php quote escapes", instead of what I just did?
(by the way how to write "php quote escapes"?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,有人会说单引号字符串比双引号字符串更快;您不应该关心这种微优化:它不会对您的应用程序产生任何影响。
单引号字符串和双引号字符串之间的区别是:
\n
、\ t
, ...作为参考,在 PHP 手册中:
我认为,一般而言,这主要是个人喜好的问题...
就个人而言,在您所描述的情况下,我会使用双引号字符串,就像您所做的那样:它使代码更容易既可以写也可以读,因为您不必逃避这句话。
First of all, some people will say that simple-quoted strings are faster that double-quoted strings ; you should not care about that kind of micro-optimization : it will not make any difference for your application.
The difference between simple-quoted and double-quoted strings is :
\n
,\t
, ...For reference, in the PHP manual :
I would that that, in the general matter, it's mostly a matter of personnal preferences...
Personnaly, in a situation such as the one you described, I would use a double-quoted string, like you did : it make the code easier to both write and read, as you don't have to escape that quote.
假设您不需要双引号特殊功能,请执行最具可读性的操作。对我来说,这是使用字符串中出现最少的字符串的引号。
Do whatever is most readable, assuming you don't need the double-quote special features. For me, that's using whichever quotes for the string that appear the least in the string.