php 字符串处理
来源:互联网 发布:富士康网络重复报名 编辑:程序博客网 时间:2024/06/08 17:27
一 字符串格式化
1.trim() 可以出去字符串开始位置和结束位置的空格,并返回结果字符串
ltrim() 除去左边空格
rtrim() 除去右边空格
2.nl2br()
用<br />代替字符串中的换行符
3.printf() 将一个格式化的字符串输出到浏览器中
sprintf() 返回一个格式化的字符串
例:printf("Total amount of order is %.2f",$total);
转换说明所遵循的格式
%['填充字符][-][width][.precision]type
4.大小写
strtoupper()
strtolower
Ucfirst() 如果字符串的第一个字符是字母,则转为大写
Ucwords() 将每个单词的第一个字母转换为大写
5.格式化字符串以便存储
addslashes()
stripslashes()
二.连接和分割字符串
1.explode()分割 函数原型 array explode(string separator, string input,[,int limit]);
例: $email_array=explode('@',$email);
2.implode()和join()连接
例:$new_email=implode('@',$email_array);
3.strtok() 一次只从字符串中取出一些片段(成为令牌) 函数原型 string strok(string input, string separator);
4.
$string
, int $start
[, int $length
] )返回字符串 string
由 start
和 length
参数指定的子字符串。
start为正数 得到从起点到字符串结束的整个字符串
start为负数 得到字符串尾部的一段字符串,字符个数等于给定负数的绝对值
<?php
$rest = substr("abcdef", -1); // 返回 "f"
$rest = substr("abcdef", -2); // 返回 "ef"
$rest = substr("abcdef", -3, 1); // 返回 "d"
?>
length为正数 字符的个数
length为负数 字符串序列的尾部
<?php
$rest = substr("abcdef", 0, -1); // 返回 "abcde"
$rest = substr("abcdef", 2, -1); // 返回 "cde"
$rest = substr("abcdef", 4, -4); // 返回 ""
$rest = substr("abcdef", -3, -1); // 返回 "de"
?>
三. 字符串的比较
strcmp()
strcasecmp()
strnatcmp()
strnatcasecmp()
strlen()
四、 字符串函数匹配和替换子字符串
strstr()
stristr()
strchr()
strrchr()
strpos()
strrpos()
str_replace()
substr_replace()
- PHP字符串处理函数
- php字符串处理函数库
- php字符串处理函数库
- php字符串处理函数
- PHP字符串处理函数
- PHP 字符串处理【索引】
- php 字符串处理
- PHP 字符串处理
- 【php】字符串处理函数
- PHP字符串处理
- PHP字符串处理函数
- php 常用字符串处理
- php中文字符串处理
- php (十九)字符串处理
- php 字符串处理
- php字符串处理函数
- PHP批量处理字符串
- PHP 字符串处理
- 我的首个电子书软件--嘎嘎读书 的开发(五)
- 深入理解计算机系统--第二章(读书笔记)
- Leetcode 3Sum
- WinCE 系统界面修改偏方(一)
- 【转】hive中的LEFT SEMI JOIN
- php 字符串处理
- 【九度】并查集题目整理
- 使Eclipse的代码编辑器变得更智能
- 设置easyui菜单项不可用
- Debug Android and Linux suspend and resume
- Oracle RMAN Recover中使用BBED 跳过缺失的归档 继续 Recover 的测试 .
- android: binder
- Spring Aop实例之AspectJ注解配置
- 分析av_read_frame、av_read_frame_internal和av_read_packet的主要步骤