CH5---php从入门到精通

来源:互联网 发布:拿破仑全面战争mac 编辑:程序博客网 时间:2024/04/27 04:24
 <?php header("Content-type:text/html;charset=utf8");echo "<br/>-------------------------<br/>";echo "fruit\rpear\napple\tbanana";//linux和widows有区别的;echo "<br/>-----------自动转义字符;--------------<br/>";$str = "select * from tb_book where bookname='PHP从入门到精通'";echo $str."<br/>";$a = addslashes($str);echo $a."<br/>";$b = stripslashes($a);echo $b;echo "<br/>-----------对指定字符串转义-这个用法仅限于开始结束都包含里面?-------------<br/>";$a = "编程体验网";echo $a;echo "<br/>";$b = addcslashes($a,"编程体验网");echo $b;echo "<br/>";$c = stripcslashes($b);echo $c;echo "<br/>-------------------------<br/>";echo strlen("编程:www.bcty365.com");echo "<br/>------------substr-------------<br/>";echo substr("She is a girl",0);echo "<br/>";echo substr("She is a girl",4,14);echo "<br/>";echo substr("She is a girl",-4,4);//从-4向后截取4位;echo "<br/>";echo substr("She is a girl",0,-4);//从0 到 -4位置的截取echo "<br/>";echo "<br/>----------strcmp按照字节比较字符串大小---------------<br/>";$str1 = "明日编程词典";$str2 = "明日编程词典";$str3 = "mrsoft";$str4 = "MRSOFT";echo strcmp($str1,$str2);echo strcmp($str3,$str4);echo strcasecmp($str3,$str4);//不用区分大小写;echo "<br/>---------strnatcmp按照字符串中数字大小比较;----------------<br/>";$str1 = "str2.jpg";$str2 = "str10.jpg";$str3 = "mrsoft1";$str4 = "MRSOFT2";echo strcmp($str1,$str2);echo strcmp($str3,$str4);echo strnatcmp($str1,$str2);echo strnatcmp($str3,$str4);echo "<br/>-----------strncmp在指定位置比较大小;--------------<br/>";$str1 = "I like PHP!";$str2 = "i an fine !";echo strncmp($str1,$str2,2);echo "<br/>----------strstr---------------<br/>";$str = "ioewio.ew.jpg";echo strstr($str,'.');echo "<br/>";echo strchr($str,'.');echo "<br/>--------substr_count字符串中某字符串出现的次数;-----------------<br/>";$str = "明日编程词典词";echo substr_count($str,"词");echo "<br/>----------str_ireplace(search, replace, subject)---------------<br/>";$contents = "白领女子公寓,温馨街南行200米,交通便利,亲情化专人管理,您的理想选择!";$str="女子公寓";echo str_replace($str,"<font color='#FF0000'>".$str."</font>",$contents);echo "<br/>----------substr_replace---书中gb的编码一个汉字占2个字符,这3个------------<br/>";//header("Content-type:text/html;charset=gb2312");$str = "用今日的辛勤工作,换明日的双倍回报!";$replace = "百倍";echo strlen($replace);//书中gb的编码一个汉字占2个字符,这3个;echo substr_replace($str, $replace,39,6);echo "<br/>-----------number_format--------------<br/>";$num = 1868.954;echo number_format($num);echo "<br/>";echo number_format($num,2);//1,868.95echo "<br/>";$num2 = 11886655.760055;echo number_format($num2,2,'*',',');//11,886,655*76//*小数点位置, ','为分割位;echo "<br/>";echo number_format($num2,2,'.',',');//11,886,655.76echo "<br/>";echo number_format($num2,2,'.','.');//11.886.655.76echo "<br/>---------trim----p96练习题1------------<br/>";$str="&&  明日编程词典  &&";echo $str."<br/>";echo trim($str,"&&  &&")."kk";echo "<br/>-------------------------<br/>";$str = "\r\r(:@_@ 创图书编辑伟业 展软件开发雄风 @_@:)         ";echo trim($str)."find space";echo "<br/>";echo trim($str,"\r\r(::)")."find space";//空格没去,左右两边的:)都去了;echo "<br/>-----------p96练习题2--------------<br/>";$_POST['IDcard'] = "321323198902123336";if((strlen($_POST['IDcard'])<>15)&&(strlen($_POST['IDcard'])<>18)){                      //检测用户身份证号的长度是否正确    echo "<script>alert('用户身份证号标准长度为15位或18位才合法!');</script>";}else{    echo "用户信息输入合法!";}echo "<br/>----------p96练习题3---------------<br/>";$text="白领女子公寓,温馨街南行200米,交通便利,亲情化专人管理,您的理想选择!";$content="女子";echo str_ireplace($content,"<font color='red'><strong>".$content."</strong></font>",$text); echo "<br/>-----------p96练习题4---explode--------------<br/>";$content = "北京,上海,天津,重庆,河北,山西,辽宁,吉林,黑龙江,江苏,浙江,安徽,福建,江西,山东,河南,湖北,湖南,其他";$data=explode(",",$content);for($index=0;$index<count($data);$index++){    echo $data[$index];    echo "</br>";} ?>

0 0
原创粉丝点击