网站制作学习网PHP→正文:php常用字符串操作
字体:

php常用字符串操作

PHP 2010/5/30 14:07:53  点击:不统计


php常用的字符串整理函数,
chop($forasp_str,参数); 返回 从字符串$forasp_str右边开始,去除等于参数的字符
举例:<?php $str = "this site is www.forasp.cn !oo";echo chop($str,"o");?>输出:this site is www.forasp !
trim($forasp_str);返回 将字符串$forasp_str开始位置和结束位置的字符串
举例:<?php $str = " this site is www.forasp.cn!  ";echo chop($str,"o");?>输出:this site is www.forasp! 开始结束都有空格,用trim后两边都么有空格
ltrim($forasp_str)和rtrim($forasp_str);返回去除左边开始和去除偶编开始空格字符串.

php格式化字符串
nl2br()函数:在字符串的每个新行前插入HTML换行标志。
举例:<?php $str = "this site is \n www.forasp.cn !oo";echo nl2br($str);?>输出:this site is <br> www.forasp !将原来的换行符号替换为html中<br>换行符号.
print():输出字符串,跟echo类似,但是该函数具有返回值,true或者false.
printf():输出一个格式化的字符串.这个是输出,
sprintf():返回一个格式化的字符串.这个是返回

<?php
$name = "forasp.cn";
$str = "this site is $name";
print($str);//输出this site is forasp.cn
printf("this site is %s",$name);//this site is forasp.cn,其中%s是转换说明,用一个字符串来替换,可以有多个替换参数
echo sprintf("this site is %s",$name);//返回值后在输出this site is forasp.cn
?>
printf 后面转换说明
%类型   意义
b   整数并作二进制输出
c   整数并作字符串输出
d   整数并作小数输出
f   双精度并作浮点数输出
o   整数并作八进制输出
s   字符串作为字符输出
u    整数作为非指定小数输出
x   整数作为嗲有小写字母a-f的十六进制输出
X   整数带有大写字母A-F的十六进制输出原载于:网站制作学习网Foasp.cn

addslashes(),stripslashes(),花哟用于转义字符串函数,第一个是转义函数,第二个是输出的时候对字符串就进行反转义.

php字符大小写转换
strtoupper($forasp_str); 将字符串$forasp_str中的字母转换为大写
strtolower($forasp_str); 将字符串$forasp_str中的字母转换为小写
ucfirst($forasp_str); 将字符串的第一个字母转换为大写
ucword($forasp_str);将字符串中的每个单词的第一个字母转换为大写


转www.载for网站制作学习asp必.cn究

·上一篇:php数组的其他方法 >>    ·下一篇:php分割字符串 >>
推荐文章
最新文章