PHP restricts long sentence titles and replaces the code for the following words with "..." _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.