【发布时间】:2013-12-17 09:58:38
【问题描述】:
尝试创建一个省略号,首先显示字符串的一部分,然后单击函数后显示字符串的其余部分。
找到了许多创建省略号函数的教程,但尝试了很长时间如何从结尾部分获取整个单词。
我试过这样做
<?php
$text="Lorem ipsum dolor sit amet.";
// 123456789
echo substr($text,0,9); // result: "Lorem ips"
echo '<hr>';
$start = substr($text,0,9);
// now this preg_replace() is awesome cause its only returning the entire word
echo preg_replace('/\w+$/','',$start); //result: "Lorem"
echo '<hr>';
echo substr($text,9,strlen($text)); //result: "um dolor sit amet."
// now how should this preg_replace be to get result "ipsum dolor sit amet."
?>
所以问题是:如何使用这个preg_replace() 来得到结果"ipsum dolor sit amet."。
我尝试过更改 preg_replace('/\$+w/','',$start); 之类的内容,但我不知道如何编写该正则表达式。
【问题讨论】:
标签: php regex preg-replace