PHP中的双引号和单引号有什么区别? [英] What is the difference between double and single quotes in PHP?

查看:33
本文介绍了PHP中的双引号和单引号有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
php中单引号和双引号字符串的区别

我是 PHP 新手,在编程中我见过 "" 和 ' '.

I am new to PHP and in programming i have seen use of both "" and ' '.

"和""有什么区别?

在声明链接时,我使用了以下内容,但它似乎不起作用,引用中一定有问题:

And in declaring a link i have used the following ,but it does not seem to work there must be something wrong in quotation:

$abc_output .='<a href="abc.com">' Back to Main Menu'</a>';

echo $abc_output;  

这里可能有什么错误?

推荐答案

您希望将文本保留在字符串中:

You want to keep the text inside of your string:

$abc_output .='<a href="abc.com">Back to Main Menu</a>';

<小时>

'" 之间的区别在于您可以将变量嵌入双引号字符串中.


The difference between ' and " is that you can embed variables inside of a double quoted string.

例如:

$name = 'John';
$sentence = "$name just left"; // John just left

如果要使用单引号,则必须连接:

If you were to use single quotes, then you'd have to concatenate:

$name = 'John';
$sentence = $name.' just left'; // John just left

<小时>

PS:不要忘记你总是要转义你的引号.下面2个是一样的:


PS: Don't forget that you always have to escape your quotes. The following 2 are the same:

$double = "I'm going out"; // I'm going out
$single = 'I\'m going out'; // I'm going out

反之亦然:

$single = 'I said "Get out!!"'; // I said "Get out!!"
$double = "I said \"Get out!!\""; // I said "Get out!!"

这篇关于PHP中的双引号和单引号有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆