PHP
发布时间:2022-04-09 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php的字符串用法小结,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1 求长度,最基本的
$text = "sunny day";
$count = strlen($text
); // $count = 9
2 字符串截取
截取前多少个字符
$article = "BREAKING NEWS: In ultimate irony,man bites dog."; $sum
Mary = substr_
replace($article,"...",40
); 3 算单词数
$article = "BREAKING NEWS: In ultimate irony,man bites dog."; $wordCount = str_word_count($articl
E);
// $wordCount = 8
4 将字符串变成HTML的连接
$url = "W.J. Gilmore,LLC (//code.js-code.com)";
$url = preg_
replace("/
http://([A-z
0-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 con
Tinent,a new nation,conceived in Liberty,and de
Dicated to the proposition that all men are created equa
l.";
echo wordwrap($speech,30
); 输出:
Four
score and seven years ago our fathers brought forth,and de
Dicated to the proposition that all men are created equa
l.大佬总结
以上是大佬教程为你收集整理的php的字符串用法小结全部内容,希望文章能够帮你解决php的字符串用法小结所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。