首页 >后端开发 >php教程 >非常好的php分行程序--可以按指定的字数分行_PHP教程

非常好的php分行程序--可以按指定的字数分行_PHP教程

WBOY
WBOY原创
2016-07-13 17:23:461147浏览

可以按您指定的每行字数来断行,比较方便,有一定用处。
// text_wrap( $text, $max_width, $html_type )
// $text 要格式的东西
// $max_width - 格式的长度
// $html_type 格式的方式
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";
}
// 下面是个测试,你将这篇文章另存试一下

$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"); //调用函数
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/532218.htmlTechArticle可以按您指定的每行字数来断行,比较方便,有一定用处。 // text_wrap( $text, $max_width, $html_type ) // $text 要格式的东西 // $max_width - 格式的长度...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn