php省略号,以preg_replace开头和结尾的整个单词

该死的

试图创建省略号,仅显示部分字符串,然后单击功能后显示其余部分。

找到了许多创建ellispis函数的教程,但是尝试了很长时间,如何从结尾部分​​获得整个单词。

我已经试过这样

<?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);但我不知道如何编写该正则表达式。

preg_replace('/^\w+\s/','',$text)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章