php笔记

来源:互联网 发布:成都华为软件工厂 编辑:程序博客网 时间:2024/05/16 14:12

printf()

 

int printf(string format[,mixed ...])

example

<?php

    $str="aaa";

    $str2="bbb";

    $str3="ccc";

    printf("我是%s你是%s他是%s",$str,$str2,$str3);

?>

 

sprintf()

 

string printf(string format[,mixed....])

example

<?php

    $sql="insert into user values('%s','%s','%s','%s')"

    $sql=sprintf($sql,"1","zhang","male","06");

?>

 

$test="iwind";
$str = "i love$test";
$str1 = 'i love $test';
echo
$str; //将得到 i love iwind
echo $str1;//将得到 i love $test
echo$str="test";//一方面输出test,一方面把"test"赋给字符串变量 $str
print $str="test";

两者除了名字不一样外,还是有其它区别的。print具有返回值,一直返回1,而echo没有,所以echo比print要快一些: ,也正因为这个原因,print能应用于复合语句中,而echo不能