非常好的php分行程序--可以按指定的字数分行
时间:2007-02-17 来源:PHP爱好者
可以按您指定的每行字数来断行,比较方便,有一定用处。
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
<?php
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// text_wrap( $text, $max_width, $html_type )
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $text 要格式的东西
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $max_width - 格式的长度
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $html_type 格式的方式
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
Function text_wrap( $text, $max_width, $html_type )
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
{
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $cnt keeps track of the position of t
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// he last break
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$cnt = 0;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
if (!strcmp("PRE", $html_type))
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line_break = "n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
else
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line_break = "<BR>n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo "<$html_type>n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
for ($i = $max_width; $i <strlen($text); $i += $max_width)
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
{
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$width = $max_width;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
while ($text[$i] != ' ' && $text[$i] != 'n' && $text != 't')
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
{
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$i--;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$width--;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
}
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo substr($text, $cnt, $width),$line_break;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$cnt = $i+1;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
}
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$last_line = substr($text, $cnt);
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
if ($last_line[0] != ' ')
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo substr($text, $cnt);
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
else
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo substr($text, $cnt+1);
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo "</$html_type>n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
}
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// 下面是个测试,你将这篇文章另存试一下
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = ""When considering the use of a server side";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line language, such as php3, you have to weigh";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line the load on your server against the benefits";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line of the language. For many, especially with";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line regards to php3, the benefits are worth the";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line sacrifice. For some tasks it is unimaginable";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line how difficult they would be without server side";
$line = "$line scripting. There is certainly something to be";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line said for web content that is dynamic -- it";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line keeps people coming back." -- The Webmaster";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
text_wrap($line, 60, "BLOCKQUOTE"); //调用函数
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
?>
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
php爱好者站 http://www.phpfans.net 网页特效|网页模板
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
<?php
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// text_wrap( $text, $max_width, $html_type )
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $text 要格式的东西
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $max_width - 格式的长度
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $html_type 格式的方式
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
Function text_wrap( $text, $max_width, $html_type )
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
{
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// $cnt keeps track of the position of t
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// he last break
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$cnt = 0;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
if (!strcmp("PRE", $html_type))
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line_break = "n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
else
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line_break = "<BR>n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo "<$html_type>n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
for ($i = $max_width; $i <strlen($text); $i += $max_width)
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
{
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$width = $max_width;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
while ($text[$i] != ' ' && $text[$i] != 'n' && $text != 't')
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
{
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$i--;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$width--;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
}
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo substr($text, $cnt, $width),$line_break;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$cnt = $i+1;
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
}
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$last_line = substr($text, $cnt);
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
if ($last_line[0] != ' ')
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo substr($text, $cnt);
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
else
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo substr($text, $cnt+1);
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
echo "</$html_type>n";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
}
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
// 下面是个测试,你将这篇文章另存试一下
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = ""When considering the use of a server side";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line language, such as php3, you have to weigh";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line the load on your server against the benefits";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line of the language. For many, especially with";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line regards to php3, the benefits are worth the";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line sacrifice. For some tasks it is unimaginable";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line how difficult they would be without server side";
$line = "$line scripting. There is certainly something to be";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line said for web content that is dynamic -- it";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
$line = "$line keeps people coming back." -- The Webmaster";
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
text_wrap($line, 60, "BLOCKQUOTE"); //调用函数
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
?>
chi na it p owe r .comrp3aKI9yNiPxPxzdN9GPVmfa4
php爱好者站 http://www.phpfans.net 网页特效|网页模板
相关阅读 更多 +