插件1:文本换行
来源:互联网 发布:手机登陆电脑版淘宝 编辑:程序博客网 时间:2024/06/10 13:36
<?php // Plug-in 1: Wrap Text// This is an executable example with additional code supplied// To obtain just the plug-ins please click on the Download link$text = "Treats of the place where Oliver Twist was born, and of the circumstances attending his birth.\nAmong other public buildings in a certain town, which for many reasons it will be prudent to refrain from mentioning, and to which I will assign no fictitious name, there is one anciently common to most towns, great or small: to wit, a workhouse; and in this workhouse was born; on a day and date which I need not trouble myself to repeat, inasmuch as it can be of no possible consequence to the reader, in this stage of the business at all events; the item of mortality whose name is prefixed to the head of this chapter.\nFor a long time after it was ushered into this world of sorrow and trouble, by the parish surgeon, it remained a matter of considerable doubt whether the child would survive to bear any name at all; in which case it is somewhat more than probable that these memoirs would never have appeared; or, if they had, that being comprised within a couple of pages, they would have possessed the inestimable merit of being the most concise and faithful specimen of biography, extant in the literature of any age or country.";echo "<font face='Courier New' size='2'>";echo PIPHP_WrapText($text, 71, 5);function PIPHP_WrapText($text, $width, $indent){ // Plug-in 1: Wrap Text // // This plug-in takes a string variable containing any // text and then adds <br /> and tags in the right // places to make the text wrap and indent para starts. // The arguments required are: // // $text: Text to be modified // $width: Number of characters art which to wrap // $indent: Number of chars to indent para start $wrapped = ""; $paragraphs = explode("\n", $text); foreach($paragraphs as $paragraph) { if ($indent > 0) $wrapped .= str_repeat(" ", $indent); $words = explode(" ", $paragraph); $len = $indent; foreach($words as $word) { $wlen = strlen($word); if (($len + $wlen) < $width) { $wrapped .= "$word "; $len += $wlen + 1; } else { $wrapped = trim($wrapped); $wrapped .= "<br />\n$word "; $len = $wlen; } } $wrapped = trim($wrapped); $wrapped .= "<br />\n"; } return $wrapped;}?>
1.插件说明:
插件1接受一个任意的字符串变量,在合适的位置插入<br/>和" ",并且设置段首缩进一定距离。它需要三个参数:
$text:需要换行的字符串变量。
$width:整数,表示在这个位置强制文本换行。
$indent:整数,表示段首缩进的字符个数
- 插件1:文本换行
- eclipse 文本换行工具插件
- cocos2d-android-1文本字符串的换行
- 文本自动换行
- 强制文本换行
- Asp.Net文本换行
- 强制文本自动换行
- 文本不充许换行
- 文本自动换行
- 超链接title文本换行
- Flex 文本换行
- svg 文本换行
- 文本自动换行问题
- JLabel文本换行
- CSS 文本强行换行
- GridView文本自动换行
- 显示文本自动换行
- 水晶报表,文本换行.
- 获取IP地址
- wpf中datagrid的双击事件
- 判断单链表是否存在环,判断两个链表是否相交问题详解
- DotNetBar的SuperTooltip控件使用技巧
- 找寻二叉树中两个节点的公共父节点中最近的那个节点的三种情况
- 插件1:文本换行
- C# 匿名类型
- 计算机硬件运作总结
- poj 3250 Bad Hair Day 栈的简单运用
- 怎么防止类被继承?对于不能被继承的类,怎么初始化及销毁它的实例?
- 大数相乘算法
- linux和unix下常用解压和压缩命令
- 栈的push、pop序列
- 关于数组的几道面试题