php字符串

WBOY
Release: 2016-06-23 14:33:38
Original
934 people have browsed it

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

echo strlen($str);
Copy after login

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

echo strtoupper($str);echo strtolower($str);
Copy after login

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

echo trim($str);
Copy after login

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

echo strrev($str);
Copy after login

5. 格式化输出:

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

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

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

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

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

printf("%b",10);printf("%o",10);printf("%X",10);
Copy after login

d) 输出a的ASCII码

echo ord("a");
Copy after login

e) 输出ASCII码98的字符

echo chr(97);printf("%c",97);
Copy after login

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

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

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

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

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

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

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template