惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Y
Y Combinator Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
S
SegmentFault 最新的问题
J
Java Code Geeks
V
Visual Studio Blog
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
B
Blog RSS Feed
The Cloudflare Blog
MyScale Blog
MyScale Blog
月光博客
月光博客
Microsoft Security Blog
Microsoft Security Blog
美团技术团队

博客园 - jackyrong的世界

本BLOG迁移到javaeye .net中javascript去调用webservice - jackyrong的世界 - 博客园 asp.net 4中的新特性之一:控制URL长度 vs.net 2010中使用code snippets - jackyrong的世界 asp.net 2010中jquery调用webservice 一个模仿HTML5功能的jquery控件 - jackyrong的世界 - 博客园 php中存储IP的一个不错的方法 介绍又一个不错的TOMCAT监控好工具probe jquery中输入验证中一个不错的效果 - jackyrong的世界 - 博客园 软件工程心理学系列11之如何应对客户的严厉批评 团队中不能只有梅西呀 mysql 性能学习1 6个PHP漏洞扫描工具 监控JAVA应用的好工具javamelody (转)Math.Round() -- c# 与 java的区别 云估算? apache 的mod-status 如何带平均年龄小的团队 本人售买一本o'relliy 出版社的《WCF服务编程》书,有意的广州朋友当面交易
小结php的字符串用法 - jackyrong的世界 - 博客园
jackyrong的世界 · 2010-06-05 · via 博客园 - jackyrong的世界

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 (http://www.wjgilmore.com)";
$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.