This code can be used to limit the length of a sentence, and to "..." instead of the following words, which is appropriate to limit the title of the article.
$str = "This is a verrrrrrryyyyy long string. This is a verrrrrrryyyyy long string. "; /Long string
$no _of_words = 7;//Sets the number of words to limit
$str _array = Split ("", $str, $no _of_words+1);//divide sentences with spaces
if (count ($str _array) > $no _of_words) {//Determine if the number of words in the original string is greater than the number of words set
for ($i =0; $i < $no _of_words; $i + +) {//If the number of word strings is greater than the set value
Print $str _array[$i]. " "; } Print the word out to the set value
Print "
..... (more)";} Print ellipsis when you reach the Set value ... and add a more to do hints
else {//otherwise if the number of words in the original string is less than the set value
Print $str; }//that, of course, prints out the whole string, cough, which is also said.
?>
http://www.bkjia.com/PHPjc/532179.html www.bkjia.com true http://www.bkjia.com/PHPjc/532179.html techarticle //This code can be used to limit a long sentence, and to "..." instead of the following words, suitable to limit the length of the article title $str = "This is a verrrrrrryyyyy long string. This I ...