php字符串

WBOY
WBOYOriginal
2016-06-23 14:33:38990browse

1.  获取表单提交的字符串长度   strlen     

echo strlen($str);

 

2.  把表单提交的字符串全部用大写和小写显示出来    strtoupper     strtolower

echo strtoupper($str);echo strtolower($str);

 

3.  去除掉表单提交的字符串首尾的空格    trim

echo trim($str);

 

4.  把表单提交的字符串逆序显示出来    strrev

echo strrev($str);

 

5.  格式化输出:

a)         字符串输出长度为20,长度不够在前面补充@

echo str_pad($str,50,"@",STR_PAD_LEFT);printf("%'@50s",$str);

 

b)        小数输出长度为10,小数位占5,长度不够在前面补充#

printf("%'#11.5f",$num);

 

c)         分别输出整数10的二进制、八进制、十六进制形式

printf("%b",10);printf("%o",10);printf("%X",10);

 

d)        输出a的ASCII码

echo ord("a");

 

e)         输出ASCII码98的字符

echo chr(97);printf("%c",97);

 

6.  用php字符串函数去掉未知长度的字符串的最后两位

echo substr($str,0,strlen($str)-12);

 

7.  把表单提交的多个字符串用@连接起来

$arr = array("abc","a","c");echo implode("@",$arr);

 

8.  把alex0018@126.com字符串拆开变为两个字符串,用户名和服务器名

$email = "alex0018@126.com";$arremail = explode("@",$email);echo $arremail[0];echo $arremail[1];

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP的优点Next article:php学习??smarty