php的字符串用法小结
作者:bea
1 求长度,最基本的 $text = "sunny day"; $count = strlen($text); // $count = 9 2 字符串截取 截取前多少个字符 $article = "BREAKING NEWS: In ultimate irony, man bites dog."; $summary = substr_replace($article, "...", 40); 3 算单词数 $article = "BREAKING NEWS: In ultim
1 求长度,最基本的
$text = "sunny day";
$count = strlen($text); // $count = 9
2 字符串截取
截取前多少个字符
$article = "BREAKING NEWS: In ultimate irony, man bites dog."; $summary = substr_replace($article, "...", 40);
3 算单词数
$article = "BREAKING NEWS: In ultimate irony, man bites dog."; $wordCount = str_word_count($article);
// $wordCount = 8
4 将字符串变成HTML的连接
$url = "W.J. Gilmore, LLC ()";
$url = preg_replace("/http://([A-z0-9./-]+)/", "$0", $url);
5 去除字符中的HTML字符串
$text = strip_tags($input, "
");
6 nl2br:
$comment = nl2br($comment);
变成带HTML格式
7 Wordwrap
限制每行字数
$speech = "Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.";
echo wordwrap($speech, 30);
输出:
Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
有用 |
无用
$text = "sunny day";
$count = strlen($text); // $count = 9
2 字符串截取
截取前多少个字符
$article = "BREAKING NEWS: In ultimate irony, man bites dog."; $summary = substr_replace($article, "...", 40);
3 算单词数
$article = "BREAKING NEWS: In ultimate irony, man bites dog."; $wordCount = str_word_count($article);
// $wordCount = 8
4 将字符串变成HTML的连接
$url = "W.J. Gilmore, LLC ()";
$url = preg_replace("/http://([A-z0-9./-]+)/", "$0", $url);
5 去除字符中的HTML字符串
$text = strip_tags($input, "
");
6 nl2br:
$comment = nl2br($comment);
变成带HTML格式
7 Wordwrap
限制每行字数
$speech = "Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.";
echo wordwrap($speech, 30);
输出:
Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
猜你喜欢
您可能感兴趣的文章:
- PHP+ACCESS 文章管理程序代码
- php $_SERVER["REQUEST_URI"]获取值的通用解决方法
- php自动加载的两种实现方法
- PHP定时自动生成静态HTML的实现代码
- PHP XML操作的各种方法解析(比较详细)
- PHP操作xml代码
- PHP XML error parsing SOAP payload on line 1
- PHP zlib扩展实现页面GZIP压缩输出
- PHP,ASP.JAVA,JAVA代码格式化工具整理
- PHP迅雷、快车、旋风下载专用链转换代码
- PHP中实现汉字转区位码应用源码实例解析
- joomla内置的表单验证功能使用方法
- 实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法
- Php获取金书网的书名的实现代码
- PHP中json_encode、json_decode与serialize、unserialize的性能测试分析
- php网站来路获取代码(针对搜索引擎)
- php数组对百万数据进行排除重复数据的实现代码
- 腾讯QQ php程序员面试题目整理
- php 上传文件类型判断函数(避免上传漏洞 )