了解单引号和双引号 (.)、(") 和 (')

发布于 2024-09-17 16:41:34 字数 182 浏览 7 评论 0 原文

你能告诉我在 (")quotes 中使用 (')singlequotes 和在 ( 中使用 (")quotes 有什么不同吗')单引号?在 concat 中,这个 '".$bla."' 的含义是什么,我仍然无法区分它们。

Can you tell me what is the different using (')single quotes inside (")quotes and (")quotes inside (')single quotes? and at concat, what is the meaning of this '".$bla."' I still can not distinguish them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

欲拥i 2024-09-24 16:41:34

在 SQL 中,任何带有单引号的内容都被视为基于文本的数据类型。

SQL 使用双引号来转义关键字和非 ASCII 字符。

这是:

'". $bla ."'

..是 PHP 语法。 $bla 是一个 PHP 变量,句点是一个字符串连接字符(这就是为什么两边都有一个)。因此,在此示例中, $bla 变量的内容被连接成一个字符串,并用单引号引起来。

In SQL, anything with single quotes is considered a text based data type.

SQL uses double quotes for escaping keywords and non-ASCII characters.

This:

'". $bla ."'

..is PHP syntax. $bla is a PHP variable, the period is a string concatenation character (which is why there's one on both sides). So in this example, the content of the $bla variable is being concatenated into a string, where it will be surrounded by single quotes.

留蓝 2024-09-24 16:41:34

主要区别是双引号中的任何内容都会被评估,而单引号中的任何内容则不会。有一些讨论认为使用单引号比使用双引号更好,这样 PHP 就不需要评估该行的每个方面来确定它是否是一个变量:

$good = 'really good';

echo "this is not $good"; //bad
echo 'this is' . $good;  //good

它只会让事情运行得更快并保持代码的外观清洁工。

The main difference is the anything in a double quote is evaluated and anything in a single quote is not. There has been some discussion that it is better to use single quotes than double quotes so that PHP does not need to evaluate every aspect of the line to determine if it is a variable or not:

$good = 'really good';

echo "this is not $good"; //bad
echo 'this is' . $good;  //good

It just keeps thing running faster and keeps the code looking cleaner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文