PHP字符处理基础知识

<?php
	class StrDemo
	{
	    function StrTest()
	    {
	    	$s = "abcd";
	    	print '$s length:'.strlen($s)."<br/>";//获取字符长度
	    	$a = "abc";
	    	$b = "abC";
	    	print strcasecmp($a, $b)."<br/>";//忽略大小写比较字符串
	        print strtoupper($a);//字符转大写
	        
	        $x = "sdsd'  sdsdf
	        sdfsd<br/>
	        $$$$$$$$$@<br/>
	        ffff";
	        
	        print nl2br($x);//将字符串中的换行符转换为<br/>,即转换为html中的换行,在读取文件内容在网页中显示时极为有用
	        print htmlspecialchars($x);//函数把一些预定义的字符转换为 HTML 实体
/×
预定义的字符是:

    & (和号) 成为 &
    " (双引号) 成为 "
    ' (单引号) 成为 '
    < (小于) 成为 <
    > (大于) 成为 >
×/
	        print strip_tags($x);//去掉字符串中的所有html标记
	        
//here doc字符串的声明方式
	        $doc = <<< DOC
	        a,
	        b,
	        c,
	        d
DOC;//这里必须要顶个,DOC前面不能有空格
	        print nl2br($doc);
	        var_dump(explode(',', $doc));//explode方法将字符串按指定字符分割为字符数组。与split方法类似,但后则有启用正则匹配,所以前者速度更快
	        var_dump( implode('|',explode(',', $doc)) );//implode正好与explode相反,是将数组合成指定字符分割的字符串
	        
	    }		
	}
	
	$k = new StrDemo();
	$k->StrTest();
?>
原文地址:https://www.cnblogs.com/huangzelin/p/3504348.html