Very good php branch Program-branch by specified word count

Source: Internet
Author: User

It is convenient and useful to break a line by the number of words in each line you specify.
// Text_wrap ($ text, $ max_width, $ html_type)
// $ Text to be formatted
// $ Length of max_width-format
// $ Html_type format
Function text_wrap ($ text, $ max_width, $ html_type)
{
// $ Cnt keeps track of the position of t
// He last break
$ Cnt = 0;
If (! Strcmp ("PRE", $ html_type ))
$ Line_break = "n ";
Else
$ Line_break ="
N ";
Echo "<$ html_type> n ";
For ($ I = $ max_width; $ I <strlen ($ text); $ I + = $ max_width)
{
$ Width = $ max_width;
While ($ text [$ I]! = & $ Text [$ I]! = N & $ text [I]! = T)
{
$ I --;
$ Width --;
}
Echo substr ($ text, $ cnt, $ width), $ line_break;
$ Cnt = $ I + 1;
}
$ Last_line = substr ($ text, $ cnt );
If ($ last_line [0]! =)
Echo substr ($ text, $ cnt );
Else
Echo substr ($ text, $ cnt + 1 );
Echo" N ";
}
// Below is a test. You can save this article for another try.

$ Line = "" When considering the use of a server side ";


$ Line = "$ line language, such as php3, you have to weigh ";
$ Line = "$ line the load on your server against the benefits ";
$ Line = "$ line of the language. For example, especially ";
$ Line = "$ line regards to php3, the benefits are worth ";
$ Line = "$ line sacrifice. For some tasks it is unimaginable ";
$ Line = "$ line how difficult they wocould be without server side ";
$ Line = "$ line scripting. There is certainly something to be ";
$ Line = "$ line said for web content that is dynamic -- it ";
$ Line = "$ line keeps people coming back." -- The Webmaster ";
Text_wrap ($ line, 60, "BLOCKQUOTE"); // call a function
?>

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.