SyntaxHighlighter. all (); news & nbsp; | & nbsp; Security & nbsp; | & nbsp; Forum & nbsp; | & nbsp; download & nb
// This code can be used to limit the length of a long sentence and replace the following words with "...". it is suitable for limiting the length of the article title.
$ Str = "This is a verrrrryyyyy long string. This is a verrrrryyyyy long string."; // long string
$ No_of_words = 7; // set the maximum number of words.
$ Str_array = split ("", $ str, $ no_of_words + 1); // separate sentences with spaces
If (count ($ str_array)> $ no_of_words) {// determines whether the number of words in the original string is greater than the specified number of words.
For ($ I = 0; $ I <$ no_of_words; $ I ++) {// if the number of strings is greater than the set value
Print $ str_array [$ I]. "";} // print words one by one until the set value
Print"... (More)";} // Print the ellipsis when it reaches the set value ...... and add more for the prompt.
Else {// Otherwise, if the number of words in the original string is smaller than the set value
Print $ str;} // of course, the entire string is printed and coughed.
?>