2 字符串截取 截取前多少個字符 $article = "BREAKING NEWS: In ultimate irony, man bites dog."; $summary = substr_replace($ar " /> 青草在线视频,91蝌蚪porny成人天涯,亚洲视频www

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

php的字符串用法小結

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.jb51.NET)";
$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技術php的字符串用法小結,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 松桃| 灵宝市| 临沭县| 精河县| 霸州市| 瑞昌市| 南投市| 余姚市| 革吉县| 惠水县| 陇南市| 横山县| 七台河市| 巢湖市| 黎川县| 金山区| 门源| 汉中市| 上杭县| 蚌埠市| 四平市| 南涧| 阿鲁科尔沁旗| 和顺县| 镇康县| 广灵县| 县级市| 张家口市| 黎平县| 洛扎县| 霍城县| 西盟| 靖远县| 宁城县| 怀仁县| 昭通市| 巴南区| 饶阳县| 三亚市| 乐清市| 昌都县|