Home > Backend Development > PHP Tutorial > Very good PHP branch program--can branch according to the specified number of words_PHP tutorial

Very good PHP branch program--can branch according to the specified number of words_PHP tutorial

WBOY
Release: 2016-07-13 17:23:46
Original
1153 people have browsed it

You can break lines according to the number of words per line you specify, which is more convenient and useful.
// text_wrap( $text, $max_width, $html_type )
// $text What to format
// $max_width - the length of the 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 "n";
for ($i = $max_width; $i {
$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 "$html_type>n";
}
// The following is a test, you can save this article and try it

$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 many, especially with";
$line = "$line regards to php3, the benefits are worth the";
$line = "$line sacrifice. For some tasks it is unimaginable";
$line = "$line how difficult they would 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 function
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532218.htmlTechArticle can break lines according to the number of words per line you specify, which is more convenient and useful. // text_wrap( $text, $max_width, $html_type ) // $text is what to format // $max_width - the length of the format...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template