2 字符串截取 截取前多少個字符 $article = "BREAKING NEWS: In ultimate irony, man bites dog."; $summary = substr_replace($ar " /> a国产在线视频,欧美日韩国产不卡,欧美日韩四区

色尼玛亚洲综合影院,亚洲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的字符串用法小結,轉載需保留來源!

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

主站蜘蛛池模板: 林口县| 唐河县| 九江市| 元朗区| 吴旗县| 枞阳县| 汝南县| 漯河市| 铁力市| 芦山县| 松潘县| 海盐县| 密云县| 武隆县| 汝南县| 大兴区| 桓台县| 虎林市| 邻水| 濉溪县| 德州市| 南华县| 化隆| 玛纳斯县| 白山市| 灵石县| 鸡西市| 西青区| 永济市| 汉川市| 阳原县| 金川县| 尚义县| 开封县| 岑溪市| 麻栗坡县| 阳高县| 葫芦岛市| 永清县| 天气| 枝江市|