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

來源:互聯網
上載者:User
可以按您指定的每行字數來斷行,比較方便,有一定用處。
// 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 "<$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";
}
// 下面是個測試,你將這篇文章另存試一下

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

http://www.bkjia.com/PHPjc/532218.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532218.htmlTechArticle可以按您指定的每行字數來斷行,比較方便,有一定用處。 // text_wrap( $text, $max_width, $html_type ) // $text 要格式的東西 // $max_width - 格式的長度...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.