Correcting teacher:Guanhui
Correction status:qualified
Teacher's comments:printf函数示例是不是写错了,自己看下,整体写的可以!
$str = 'Hello World!';
echo 'This is a $str'.<br>;
//单引号中的变量不会被解析
echo 'Hello \n\r World!'.<br>;
// \n\r 代表回车换行和空格在单引号中不会被解析。
echo 'Hello "\n\r World!"'.<br>;
//在单引号创建的字符串中添加双引号可以被解析
echo 'Hello \'\n\r'\ World'.<br>;
//使用\转义符显示后面的字符串。
$str ="Hello Wordl!";
echo "This is {$str}.<br>";
echo "This is .$str.<br>";
//使用{}解析出变量,也可以使用.链接字符串。
echo "Hello \n\r world";
//双引号可以直接解析出回车和空格还有转义符。
$php="PHP.cn";
echo <<< HELLO
<span style="color:red">$php</span>
HELLO
//字符串不需要加双引号,可将HTML转移输出。非常适合html+php混编。默认双引号
$php = "PHP.cn";
echo <<< 'ABC'
This is a String
ABC;
//使用单引号,可以输出大量文本
echo "HELLO WORLD!";
print("HELLO WORLD!");
$arr = ['HTML','CSS','JS','PHP'];
print_r($arr);
$str = "Hello World";
printf($str %s,'PHP');
//%s代表字符串
vprint('SELECT * FROM '%s' LIMT %b,['PHP',20] );
$SQL=sprintf('SELECT * FROM '%S' LIMT %d','PHP',20);
echo $SQL;
$SQL=vsprintf('SELECT * FROM '%S' LIMT %d','PHP',20);
echo $SQL;
$SQL=vsprintf('SELECT * FROM '%S' LIMT %d','PHP',20);
file_put_contents('temp.txt,SQL');
ceho implode('---',['HTML','JS','JS','PHP']);
echo join('---',['HTML','JS','JS','PHP']);
$res=explode(',','localhost,root,root,utf-8,3306');
printf($res);
printf(explode(',','localhost,root,root,utf-8,3306'),2);
//使用explode对字符串转换成为数组,2表示输出数组显示的参数
print_r(list($a,$b)=[100,200]);
list($host,$username,$password)=explode(',','localhost,root,root');
echo "host={$host},username={$username}";
echo substr('abcdef',1);
//截取从b开始的字符串
echo substr('abcdef'3);
//截取从d开始的字符串
echo substr('abcdef',2,2);
//截取从c开始的后两位cd
echo substr('abcdef',-3,2);
//截取从右树第3位的两个字符串de
print_r(str_split('php中文网'),3);
print_r(str_split(mb_substr($str,0,9,'utf-8'),3));
print_r(str_getcsv('1,admin,admin@php.cn'));
$csvStr =file_get_contents('text.csv');
$arr=explode(",",$csvStr);
print_r($arr);
echo str_pad('php',10,'=',STR_PAD_BOTH);
-str_repeat 替换字符串
echo str_repeat('---|',10);
echo str_replace('php','*','php.cn,php,thinkphp',$count);
echo "<br>";
echo "被替换了".$count."次";
$str= 'http://www.php.cn';
echo trim($str,'http://');
$str= 'http://www.php.cn';
echo strpos($str,'www',2);
$str= 'http://www.php.cn';
echo strlen($str);
echo strstr('css/style.css','.');
echo ltrim(strstr('admin@qq.com','@'),'@');