这篇文章主要为大家详细介绍了PHP字符串处理的10个简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编小韵来看看吧!
1.确定一个字符串的长度代码如下:
$text = "sunny day";
$count = strlen($text); // $count = 9
代码如下:
$article = "BREAKING NEWS: In ultimate irony, man bites dog.";
$summary = substr_replace($article, "...", 40); // $summary = "BREAKING NEWS: In ultimate irony, man bi..."
代码如下:
$article = "BREAKING NEWS: In ultimate irony, man bites dog.";
$wordCount = str_word_count($article); // $wordCount = 8
代码如下:
$fh = fopen("contacts.csv", "r");
while($line = fgetcsv($fh, 1000, ","))
{ echo "Contact: {$line[1]}"; }
代码如下:
$csv = implode(",", $record);
代码如下:
$url = "W.J. Gilmore, LLC (http://www.wjgilmore.com)";
$url = preg_replace("/http://([A-z0-9./-]+)/", "$0", $url);
// $url = "W.J. Gilmore, LLC (http://www.wjgilmore.com)"
代码如下:
$text = strip_tags($input, " ");
代码如下:
$pswd = "secret";
$pswd2 = "secret";
if (! strcmp($pswd, $pswd2))
{ echo "The passwords are not identical!"; }
代码如下:
$comment = nl2br($comment);
代码如下:
$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);
本文来自:http://www.q1010.com/173/13494-0.html
注:关于PHP字符串处理的10个简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。