PHP常量及数据类型相关问题

2017-10-24  本文已影响0人  陈智涛

问题引入:PHP字符串的几种定义方式和各自的区别

<?php
$name = 'chenzhitao';
$str = 'my name\tis $name ';
print_r($str."\n");

运行结果:

chenzhitaodeMacBook-Pro:php chenzhitao$ php demo2.php
my name\tis $name

(2)双引号:
双引号可以解析变量,变量可以使用特殊字符和{}包含
双引号可以解析多有转移字符
也可以使用.连接
示例:

<?php
$name = 'chenzhitao';
$age = 26;
$str = "my name\tis $name age is {$age} ";
print_r($str."\n");
$sql = 'select * from user where name = \''.$name.'\'';
print_r($sql."\n");
$sql = "select * from user where name = '$name'";
print_r($sql."\n");

运行结果:

chenzhitaodeMacBook-Pro:php chenzhitao$ php demo2.php
my name is chenzhitao age is 26
select * from user where name = 'chenzhitao'
select * from user where name = 'chenzhitao'
上一篇下一篇

猜你喜欢

热点阅读