本章小结及案例

Original 2019-04-01 22:23:36 220
abstract:    在此章节内,PHP能通过函数进行许多字符串的操作。字符可以有诸多输出方式,能够过滤与填充、大小写转换以及特殊字符的解析,还能有查找与替换、URL、JSON处理及其诸多有用的功能,能够熟练掌握和使用这些函数能能更好完成相应的功能。<?php /**  * Created by PhpStorm.  

    在此章节内,PHP能通过函数进行许多字符串的操作。字符可以有诸多输出方式,能够过滤与填充、大小写转换以及特殊字符的解析,还能有查找与替换、URL、JSON处理及其诸多有用的功能,能够熟练掌握和使用这些函数能能更好完成相应的功能。

<?php
/**
 * Created by PhpStorm.
 * User: hp
 * Date: 2019/4/1
 * Time: 21:20
**/
$str1 = 'We have agents looking for you';
echo substr($str1,-15,7),'<br>';
$str2 = 'www.php.cn';
echo strstr($str2,'p'),'<br>';
echo strstr($str2,'.',true),'<br>';
echo strpos($str2,'php'),'<hr>';
echo str_replace('www','https://www',$str2),'<br>';
echo str_ireplace('PHp','baidu',$str2),'<br>';
echo substr_replace($str2,'com',8,3),'<br>';
echo substr_replace($str2,'',4,4),'<hr>';
$str3 = 'http://www.google.com/';
echo urlencode($str3),'<br>';
$str4 = urlencode($str3);
echo '<a href="'.$str4.'">谷歌浏览器</a>','<br>';//无法访问
echo '<a href="'.urldecode($str4).'">谷歌浏览器</a><hr>';//可以访问
$str5 = '震波女';
echo json_encode($str5),'<br>';
$str6 = ['name'=>'Daisy','age'=>27,'actor'=>'汪可盈'];
echo json_encode($str6),'<br>';
$str7 = '{"a":527,"b":814,"c":1228}';
$res = json_decode($str7);
echo '<pre>',var_export($res),'</pre><br>';


Correcting teacher:西门大官人Correction time:2019-04-02 11:15:59
Teacher's summary:程序案例不错,最好写一下使用到的函数的说明或注释

Release Notes

Popular Entries