試圖創建一個省略號只顯示部分字符串首先和字符串的其餘部分後點擊功能。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);
這樣的東西,但我不知道如何編寫該正則表達式。
真棒謝謝你!你有任何鏈接或資源來學習如何編寫這些正則表達式? – caramba
PHP Live Regex - http://www.phpliveregex.com/ – Sorbo
@caramba:要學習正則表達式,這是最好的教程之一:http://www.regular-expressions.info/tutorial.html – Enissay