开发者

basics of php strings

//i am really very confused about what is used to represent a string in php i.e. if we use double inverted开发者_StackOverflow commas it too represents string and same if use single inverted commas so "avinash" or 'avinash'........which is a string?

//and plz can u tell me about a good book to read php5 from


Double quotes (") and single quotes (') both represent strings. However, PHP doesn't treat them the same way.

In double quoted (") strings, escape sequences and variable names are expanded. In single quotes (') strings, they are not. The string is not expanded.

So, given the following:

$name = "Foo";

The following code...

$doubleQuotedString = "Hello $name.\nIt is nice to see you.";
echo $doubleQuotedString;

... will output this:

Hello Foo.
It is nice to see you.

However, the following...

$singleQuotedString = 'Hello $name.\nIt is nice to see you.';
echo $singleQuotedString;

... will output this:

Hello $name.\nIt is nice to see you.

For more information, you can read the following documentation page on strings.

PHP Documentation: Strings

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜