什麼像這樣(其他人使用explode
建議 - 所以我建議另一種解決方案):
$str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
if (preg_match('/^([^\.]*)/', $str, $matches)) {
echo $matches[1] . '.';
}
正則表達式將:
- 從字符串開頭開始:
^
- 匹配任何不是。 :
[^\.]
- 任意次數:
[^\.]*
而且,正如你在輸出端需要一個.
和.
沒有被正則表達式匹配,你必須將它添加回使用時正則表達式發現了什麼。
我們在真正的基本這裏由xD – dynamic 2011-04-07 18:44:47
索裏,但我需要知道什麼人說這:),看到爆炸和strpos這就是爲什麼我喜歡stackoverflow。 – 2011-04-07 18:48:59
你有沒有試過http://php.net/string?人們不會說你在手冊中找不到的東西 – 2011-04-07 18:59:31