heavy duty wrap包装qpi wrap card是什么么样的

gift-wrap是什么意思_gift-wrap在线翻译_gift-wrap什么意思_gift-wrap的意思_gift-wrap的翻译_英语单词大全_911查询
gift-wrap是什么意思
输入英文单词或中文词语查询其翻译,例如
gift-wrap是什么意思 gift-wrap在线翻译 gift-wrap什么意思 gift-wrap的意思 gift-wrap的翻译 gift-wrap的解释 gift-wrap的发音 gift-wrap的同义词
gift-wrap['gift,ræp]第三人称单数: ; 动词过去式: ; 过去分词: ; 现在分词: ; gift-wrap 基本解释v. 用美丽的纸张及缎带包装n. 礼物包装之包装纸gift-wrap 网络解释1. 礼品包装& & 17. foam-spary packaging 喷泡沫包装 | 18. gift-wrap 礼品包装 | 19. bag, sack 袋2. 缎带包装& & gift coupon 赠券 | gift wrap 缎带包装 | gift 赠品3. 包装纸& & gift 赠品 | gift-wrap 包装纸 | giftbook 寄赠本4. 用包装纸包装& & gift voucher 礼券 | gift-wrap 用包装纸包装 | gifted 有天资的, 有天赋的 (形)gift-wrap 网络例句1. I`d like this wallet, could you please gift-wrap it for me? & &我想买这个皮夹子,你可以帮我包起来吗?2. Can you help me gift-wrap this, please? & &请你帮我把这个东西用礼品纸包起来好吗?3. That's a good idea. Can you gift-wrap it,please? & &好主意,请给我用礼品纸包装好吗?4. A: Shall I gift-wrap it for you, madam? & &女士,您要我为您包装吗?5. Customer: Can you help me gift-wrap this, please? & &请你帮我把这个东西用礼品纸包起来好吗?6. Could you gift-wrap it for me? & &你能帮我把礼物包装起来吗?7. C:Could you please gift-wrap it for me? & &请给我包装成礼品。gift-wrap是什么意思,gift-wrap在线翻译,gift-wrap什么意思,gift-wrap的意思,gift-wrap的翻译,gift-wrap的解释,gift-wrap的发音,gift-wrap的同义词,gift-wrap的反义词,gift-wrap的例句,gift-wrap的相关词组,gift-wrap意思是什么,gift-wrap怎么翻译,单词gift-wrap是什么意思常用英语教材考试英语单词大全 (7本教材)
出国英语单词大全 (5本教材)
大学英语单词大全 (13本教材)
高中英语单词大全 (6本教材)
初中英语单词大全 (13本教材)
小学英语单词大全 (33本教材)
别人正在查
911查询 全部查询 网址:
(共20个)占卜求签
(共17个)民俗文化
(共15个)交通出行
(共10个)学习应用
(共26个)休闲娱乐
(共10个)站长工具
(共9个)身体健康
&2015  京ICP备号-6 京公网安备30 Keyboard Shortcuts?
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search(current page)
Focus search box
Change language:
Brazilian Portuguese
Chinese (Simplified)
wordwrap & Wraps a string to a given number of characters
Description
string wordwrap
( string $str
[, int $width = 75
[, string $break = &\n&
[, bool $cut = false
Parameters
The input string.
The number of characters at which the string will be wrapped.
The line is broken using the optional
break parameter.
If the cut is set to TRUE, the string is
always wrapped at or before the specified width.
So if you have
a word that is larger than the given width, it is broken apart.
(See second example). When FALSE the function does not split the word
even if the width is smaller than the word width.
Return Values
Returns the given string wrapped at the specified length.
Example #1 wordwrap() example
&?php$text&=&"The&quick&brown&fox&jumped&over&the&lazy&dog.";$newtext&=&wordwrap($text,&20,&"&br&/&\n");echo&$newtext;?&
The above example will output:
The quick brown fox&br /&
jumped over the lazy&br /&
Example #2 wordwrap() example
&?php$text&=&"A&very&long&woooooooooooord.";$newtext&=&wordwrap($text,&8,&"\n",&true);echo&"$newtext\n";?&
The above example will output:
Example #3 wordwrap() example
&?php$text&=&"A&very&long&woooooooooooooooooord.&and&something";$newtext&=&wordwrap($text,&8,&"\n",&false);echo&"$newtext\n";?&
The above example will output:
woooooooooooooooooord.
- Inserts HTML line breaks before all newlines in a string
- Split a string into smaller chunks
If you'd like to break long strings of text but avoid breaking html you may find this useful. It seems to be working for me, hope it works for you. Enjoy. :)
&?php
& & function textWrap($text) {
& & & & $new_text = '';
& & & & $text_1 = explode('&',$text);
& & & & $sizeof = sizeof($text_1);
& & & & for ($i=0; $i&$sizeof; ++$i) {
& & & & & & $text_2 = explode('&',$text_1[$i]);
& & & & & & if (!empty($text_2[0])) {
& & & & & & & & $new_text .= preg_replace('#([^\n\r .]{25})#i', '\\1& ', $text_2[0]);
& & & & & & }
& & & & & & if (!empty($text_2[1])) {
& & & & & & & & $new_text .= '&' . $text_2[1] . '&';& &
& & & & & & }
& & & & }
& & & & return $new_text;
& & }
?&
I was wondering about my CMS to break up code but only non-HTML code - I didn't found anything so I came up with this little solution:
&?php
function wordWrapIgnoreHTML($string, $length = 45, $wrapString = "\n")
&& {
& && $wrapped = '';
& && $word = '';
& && $html = false;
& && $string = (string) $string;
& && for($i=0;$i&strlen($string);$i+=1)
& && {
& & && $char = $string[$i];
& & &&
& & && if($char === '&')
& & && {
& & & && if(!empty($word))
& & & && {
& & & & && $wrapped .= $word;
& & & & && $word = '';
& & & && }
& & & &&
& & & && $html = true;
& & & && $wrapped .= $char;
& & && }
& & &&
& & && elseif($char === '&')
& & && {
& & & && $html = false;
& & & && $wrapped .= $char;
& & && }
& & &&
& & && elseif($html)
& & && {
& & & && $wrapped .= $char;
& & && }
& & &&
& & && elseif($char === ' ' || $char === "\t" || $char === "\n")
& & && {
& & & && $wrapped .= $word.$char;
& & & && $word = '';
& & && }
& & &&
& & && else
& & && {
& & & && $word .= $char;
& & & &&
& & & && if(strlen($word) & $length)
& & & && {
& & & & && $wrapped .= $word.$wrapString;
& & & & && $word = '';
& & & && }
& & && }
& && }
& & if($word !== ''){
& & & & $wrapped .= $word;
& & }
& &&
& && return $wrapped;
&& }
$str = '&a href=""&';
$str .= 'Test-STRRRRRRRRRRRRRRRRRRIIIIIIIIIIIIIIIIIIIIIIING&/a&';
$str .= '&!-- COMMENT_INSIDE_ANOTHER';
$str .= '_LONG_STRING //--&';
echo wordWrapIgnoreHTML($str, 25, '[BREAK]');
[NOTE BY danbrown AT php DOT net: Contains a bug fix provided by (jaw AT condidact DOT dk) on 02-APR-09 to address an issue where "the last word in a non-html-wrapped string will be omitted."]
These functions let you wrap strings comparing to their actual displaying width of proportional font. In this case Arial, 11px. Very handy in some cases since CSS3 is not yet completely supported. 100 strings = ~5 ms
My old sheep word wrap function (posted at the bottom of this page, is kinda old dated and this one is faster and more accurate).
&?php
$fontwidth = 11;
$chargroup[0] = array(64);
$chargroup[1] = array(37,87,119);
$chargroup[2] = array(65,71,77,79,81,86,89,109);
$chargroup[3] = array(38,66,67,68,72,75,78,82,83,85,88,90);
$chargroup[4] = array(35,36,43,48,49,50,51,52,53,54,55,56,57,60,61,62,63, 69,70,76,80,84,95,97,98,99,100,101,103,104,110,111,112, 113,115,117,118,120,121,122,126);
$chargroup[5] = array(74,94,107);
$chargroup[6] = array(34,40,41,42,45,96,102,114,123,125);
$chargroup[7] = array(44,46,47,58,59,91,92,93,116);
$chargroup[8] = array(33,39,73,105,106,108,124);
& &
$chargroup_relwidth[0] = 1; $chargroup_relwidth[1] = 0.;
$chargroup_relwidth[2] = 0.;
$chargroup_relwidth[3] = 0.;
$chargroup_relwidth[4] = 0.;
$chargroup_relwidth[5] = 0.;
$chargroup_relwidth[6] = 0.;
$chargroup_relwidth[7] = 0.;
$chargroup_relwidth[8] = 0.;
$char_relwidth = null;
for ($i=0;$i&count($chargroup);$i++){
& & for ($j=0;$j&count($chargroup[$i]);$j++){
& & & & $char_relwidth[$chargroup[$i][$j]] = $chargroup_relwidth[$i];
& & }
}
function get_str_width($str){
& & global $fontwidth,$char_relwidth;
& & $result = 0;
& & for ($i=0;$i&strlen($str);$i++){
& & & & $result += $char_relwidth[ord($str[$i])];
& & }
& & $result = $result * $fontwidth;
& & return $result;& &
function truncate_str_at_width($str, $width, $trunstr='...'){
& & global $fontwidth,$char_relwidth;& & & &
& & $trunstr_width = get_str_width($trunstr);
& & $width -= $trunstr_width;
& & $width = $width/$fontwidth;
& & $w = 0;
& & for ($i=0;$i&strlen($str);$i++){
& & & & $w += $char_relwidth[ord($str[$i])];
& & & & if ($w & $width)
& & & & & && &
& & }
& & $result = substr($str,0,$i).$trunstr;
& & return $result;
& & }
?&
Using wordwrap is usefull for formatting email-messages, but it has a disadvantage: line-breaks are often treated as whitespaces, resulting in odd behaviour including lines wrapped after just one word.To work around it I use this:&?php function linewrap($string, $width, $break, $cut) {& $array = explode("\n", $string);& $string = "";& foreach($array as $key =& $val) {&& $string .= wordwrap($val, $width, $break, $cut);&& $string .= "\n";& }& return $string; }?&I then use linewrap() instead of wordwrap()hope this helps someone
I found that wordwrap deletes the spaces it wraps on. If you want to break up a string which doesn't consist of words, you may find this behaviour undesirable, as I did when trying to wordwrap a Regular Expression to 80 characters (for display along with test string, matches, etc.).To preserve the spaces and still achieve a consistent cut length, you need to replace spaces with a suitable one-character replacement. I chose the ASCII non-printing character SUB (ASCII #26; some old telephone code meaning substitute):&?php$regex= str_replace(' ', chr(26), $regex);$regex= wordwrap($regex, 80, '&br /&', TRUE);$regex= str_replace(chr(26), ' ', $regex);?&(Of course, you need to replace 80 with your column length and '&br /&' with your break string)
Another solution to utf-8 safe wordwrap, unsing regular expressions.Pretty good performance and works in linear time.&?phpfunction utf8_wordwrap($string, $width=75, $break="\n", $cut=false){& if($cut) {& & $search = '/(.{1,'.$width.'})(?:\s|$)|(.{'.$width.'})/uS';& & $replace = '$1$2'.$break;& } else {& & $pattern = '/(?=\s)(.{1,'.$width.'})(?:\s|$)/uS';& & $replace = '$1'.$break;& }& return preg_replace($search, $replace, $string);}?&Of course don't forget to use preg_quote on the $width and $break parameters if they come from untrusted input.
Word wrap from left to right (standard) and from right to left.
&?php
function myWordWrap ($string, $length=3, $wrap=',', $from='left') {
& & if ($from=='left') $txt=wordwrap($string, $length, $wrap, true);
& & if ($from=='right') {
& & & & $arr_l=array();
& & & & for ($a=0;strlen($string)&$a;$a++) $arr_l[$a]=$string{$a};
& & & & $arr_r=array_reverse($arr_l);
& & & & $string_r='';
& & & & foreach ($arr_r as $arr_line =& $arr) $string_r.=$arr;
& & & & $string_r=wordwrap($string_r, $length, $wrap, true);
& & & & $arr_r=array();
& & & & for ($a=0;strlen($string_r)&$a;$a++) $arr_r[]=$string_r{$a};
& & & & $arr_l=array_reverse($arr_r);
& & & & $txt='';
& & & & foreach ($arr_l as $arr_line =& $arr) $txt.=$arr;
& & & & }
& & return $txt;
& & }
?&
For those interested in wrapping text to fit a width in *pixels* (instead of characters), you might find the follo particularly for line-wrapping text over dynamically-generated images.If a word is too long to squeeze into the available space, it'll hyphenate it as needed so it fits the container. This operates recursively, so ridiculously long words or names (e.g., URLs or this guy's signature - ) will still keep getting broken off after they've passed the fourth or fifth lines, or whatever.&?php& & function pixel_word_wrap($text, $width, $size, $font){& & & & if(!$text) return $text;& & & & static $mult;& & & & $mult& & =& & $mult ?: version_compare(GD_VERSION, '2.0', '&=') ? .75 : 1;& & & & $box& & =& & imagettfbbox($size * $mult, 0, $font, $text);& & & & if($box[2] - $box[0] / $mult & $width)& & return $text;& & & & $output& & & & =& & '';& & & & $length& & & & =& & 0;& & & & $words& & & & =& & preg_split('/\b(?=\S)|(?=\s)/', $text);& & & & $word_count& & =& & count($words);& & & & for($i = 0; $i & $word_count; ++$i){& & & & & & if(PHP_EOL === $words[$i])& & & & & & & & $length& & =& & 0;& & & & & & if(!$length) $words[$i]& & =& & preg_replace('/^\t+/', '', $words[$i]);& & & & & & $box& & =& & imagettfbbox($size * $mult, 0, $font, $words[$i]);& & & & & & $m& & & & =& & $box[2] - $box[0] / $mult;& & & & & & if(($diff = $width - $m) &= 0){& & & & & & & & $diff& & =& & abs($diff);& & & & & & & & if($diff - $width &= 0)& & for($s = strlen($words[$i]); $s; --$s){& & & & & & & & & & $box& & =& & imagettfbbox($size * $mult, 0, $font, substr($words[$i], 0, $s) . '-');& & & & & & & & & & if($width & ($box[2] - $box[0] / $mult) + $size){& & & & & & & & & & & & $breakpoint& & =& & $s;& & & & & & & & & & & && & & & & & & & & & }& & & & & & & & }& & & & & & & & else{& & & & & & & & & & $word_length& & =& & strlen($words[$i]);& & & & & & & & & & for($s = 0; $s & $word_length; ++$s){& & & & & & & & & & & & $box& & =& & imagettfbbox($size * $mult, 0, $font, substr($words[$i], 0, $s+1) . '-');& & & & & & & & & & & & if($width & ($box[2] - $box[0] / $mult) + $size){& & & & & & & & & & & & & & $breakpoint& & =& & $s;& & & & & & & & & & & & & && & & & & & & & & & & & }& & & & & & & & & & }& & & & & & & & }& & & & & & & & if($breakpoint){& & & & & & & & & & $w_l& & =& & substr($words[$i], 0, $s+1) . '-';& & & & & & & & & & $w_r& & =& & substr($words[$i],& && $s+1);& & & & & & & & & & $words[$i]& & =& & $w_l;& & & & & & & & & & array_splice($words, $i+1, 0, $w_r);& & & & & & & & & & ++$word_count;& & & & & & & & & & $box& & =& & imagettfbbox($size * $mult, 0, $font, $w_l);& & & & & & & & & & $m& & & & =& & $box[2] - $box[0] / $mult;& & & & & & & & }& & & & & & }& & & & & & if($length & 0 && $length + $m &= $width){& & & & & & & & $output& & .=& & PHP_EOL;& & & & & & & & $length& & =& & 0;& & & & & & & & if(' ' === $words[$i])& & & & & & }& & & & & & $output& & .=& & $words[$i];& & & & & & $length +=& & $m;& & & & }& & & & return $output;& & };?&
After searching and being tired of many non-working mb_wordwrap functions at many places, I finally created a really simple and working solution&?phpfunction mb_wordwrap($string, $limit){& & $string = strip_tags($string); $string = html_entity_decode($string); $string = str_replace(array("\r", "\n"), "", $string); if(mb_strlen($string, "UTF-8") &= $limit) return $string; $last_space = mb_strrpos(mb_substr($string, 0, $limit, "UTF-8"), " ", 0, "UTF-8"); return mb_substr($string, 0, $last_space, "UTF-8").' ...'; }?&The function simply searches the last space symbol in the range and returns the string cut till that position. No iterations, no regular expressions and no buffer overload. Tested with large Russian texts and works perfectly.
I recently ran into the issue discussed by another contributor to this function (frans-jan at van-steenbeek dot R-E-M-O-V-E dot net).& The problem appeared to be how wordwrap() was treating white space.& Instead of writing my own version of wordwrap(), I discovered that the "break" parameter is not only used as the inserted string, but also used to detect the existing wrap delimiters (e.g. line endings).& If you can manage to "normalize" the wrap delimiters in your original string, you don't need to try to work-around the function wrapping at seemingly odd places (like immediately after one short word).& As one quick-and-dirty way to get wordwrap() to play nicely with most use-cases, I did this:&?php$break = strpos( $content, "\r" ) === false ? "\n" : "\r\n";$content = wordwrap( $content, 78, $break );?&I also tend to normalize multi-line strings (if my OCD is acting up).& You would typically perform this conversion _before_ sending it off to wordwrap().&?php$content = str_replace( "\r", '', $content );$content = preg_replace( "/(\r\n|\r)/", "\n", $content );$content = wordwrap( $content, 78, "\n" );?&
here is my example of UTF-8 wordwrap&?phpfunction wordwrap($str, $width, $break){& & $return = '';& & $br_width = mb_strlen($break, 'UTF-8');& & for($i = 0, $count = 0; $i & mb_strlen($str, 'UTF-8'); $i++, $count++)& & {& & & & if (mb_substr($str, $i, $br_width, 'UTF-8') == $break)& & & & {& & & & & & $count = 0;& & & & & & $return .= mb_substr($str, $i, $br_width, 'UTF-8');& & & & & & $i += $br_width - 1;& & & & }& & & & & & & & if ($count & $width)& & & & {& & & & & & $return .= $break;& & & & & & $count = 0;& & & & }& & & & & & & & $return .= mb_substr($str, $i, 1, 'UTF-8');& & }& & & & return $return;}?&
Another Word wrap from left or right :public static function myWordWrap ($string, $length=3, $wrap=',', $from='left') { & & & & if ($from=='left') $txt=wordwrap($string, $length, $wrap, true); & & & & & & if ($from=='right') {& & & & & & & & $m = strlen($string)%$& & & & & & & & if ($m & strlen($string))& & & & & & & & & & $txt = substr($string,0,$m).$wrap.wordwrap(substr($string,$m),$length, $wrap, true); & & & & & & & & else& & & & & & & & & & $txt = $& & & & & & }& & & & & & return $& & && }
The main concern when you have a text in a cell is for long words that drags the cell margins. This function will break words in a text that have more then $nr characters using the "-" char.
&?php
function processtext($text,$nr=10)
& & {
& & & & $mytext=explode(" ",trim($text));
& & & & $newtext=array();
& & & & foreach($mytext as $k=&$txt)
& & & & {
& & & & & & if (strlen($txt)&$nr)
& & & & & & {
& & & & & & & & $txt=wordwrap($txt, $nr, "-", 1);
& & & & & & }
& & & & & & $newtext[]=$txt;
& & & & }
& & & & return implode(" ",$newtext);
& & }
?&
I needed a function to justify the text - not just wrap it. I came up with this:
&?php
function justify($text, $width, $break) {
& & & & $marker = "__$%@random#$()__";
& & & & $wrapped = wordwrap($text, $width, $marker);
& & & & $lines = explode($marker, $wrapped);
& & & &
& & & & $result = "";
& & & & foreach ($lines as $line_index=&$line) {
& & & & & & & & $line = trim($line);
& & & & & & & &
& & & & & & & & $words = explode(" ", $line);
& & & & & & & & $words = array_map("trim", $words);
& & & & & & & & $wordcount = count($words);
& & & & & & & & $wordlength = strlen(implode("", $words));
& & & & & & & &
& & & & & & & & if (3*$wordlength & 2*$width) {
& & & & & & & & & & & &
& & & & & & & & }
& & & & & & & &
& & & & & & & & $spaces = $width - $wordlength;
& & & & & & & &
& & & & & & & & $index = 0;
& & & & & & & & do {
& & & & & & & & & & & & $words[$index] = $words[$index] . " ";
& & & & & & & & & & & & $index = ($index + 1) % ($wordcount - 1);
& & & & & & & & & & & & $spaces--;
& & & & & & & & } while ($spaces&0);
& & & & & & & &
& & & & & & & & $lines[$line_index] = implode("", $words);
& & & & }
& & & &
& & & & return implode($break, $lines);
}
?&
(Re: kouber at php dot net).Testing out your function, I can confirm that it works, and it works very well.However, others that intend to use your function need to be aware that if they use it in conjunction with unverified data (such as raw user input from $_POST, $_GET, etcetera), they are creating potential attack vectors that can be exploited by hackers via script requests containing malicious code. This is because your function is using the preg_replace function in conjunction with the "e" flag (in order to allow the chunk_split bit to execute), which can allow execution of arbitrary code.Solution: If there is any possibility that $str may contain unverified data (such as raw user input), ensure that the contents of $str is sanitized (such as by using htmlentities/htmlspecialchars/etc) prior to sending it to wrap($str,...).N I intend to use your function, because I like it. However, just posting this as a note to other users that may not be aware of the importance of data sanitation.
There seems to be a difference between php 5.1 and 5.2 in how wordwrap counts characters (all on Mac OSX 10.5.2):/Applications/MAMP/bin/php5/bin/php --versionPHP 5.1.6 (cli) (built: Sep& 8 :04)/Applications/MAMP/bin/php5/bin/php -r 'echo wordwrap("In aller Freundschaft (50)_UT", 20) . "\n";'In allerFreundschaft(50)_UTphp --versionPHP 5.2.5 (cli) (built: Feb 20 :47) php -r 'echo wordwrap("In aller Freundschaft (50)_UT", 20) . "\n";'In allerFreundschaft (50)_UT
Hi, this function is like wordwrap but it ignores html tags, it works like wordwrap when called with fourth parameter as true. It's based on a function I find here but improved to closer match the output of wordwrap (i.e. removed spaces at start of line) and also to improve performance. Hope it can be useful for you :-)&?phpfunction htmlwrap(&$str, $maxLength, $char='&br /&'){& & $count = 0;& & $newStr = '';& & $openTag = false;& & $lenstr = strlen($str);& & for($i=0; $i&$lenstr; $i++){& & & & $newStr .= $str{$i};& & & & if($str{$i} == '&'){& & & & & & $openTag = true;& & & & & && & & & }& & & & if(($openTag) && ($str{$i} == '&')){& & & & & & $openTag = false;& & & & & && & & & }& & & & if(!$openTag){& & & & & & if($str{$i} == ' '){& & & & & & & & if ($count == 0) {& & & & & & & & & & $newStr = substr($newStr,0, -1);& & & & & & & & & && & & & & & & & } else {& & & & & & & & & & $lastspace = $count + 1;& & & & & & & & }& & & & & & }& & & & & & $count++;& & & & & & if($count==$maxLength){& & & & & & & & if ($str{$i+1} != ' ' && $lastspace && ($lastspace & $count)) {& & & & & & & & & & $tmp = ($count - $lastspace)* -1;& & & & & & & & & & $newStr = substr($newStr,0, $tmp) . $char . substr($newStr,$tmp);& & & & & & & & & & $count = $tmp * -1;& & & & & & & & } else {& & & & & & & & & & $newStr .= $char;& & & & & & & & & & $count = 0;& & & & & & & & }& & & & & & & & $lastspace = 0;& & & & & & }& & & & }& & & }& & return $newStr;}?&
Anyone attempting to write a text email client should be aware of the following:&?php$a = "some text that must wrap nice";$a = wordwrap($a, 9);echo $a;$a = wordwrap($a, 9);echo $a;?&Subsequent uses of wordwrap() on already wrapped text will take the end-of-line characters into account when working out line length, thus reading each line that just fit nicely the first time around as being one character too long the second. This can be a problem when preparing a text email that contains (eg.) a forwarded email which has already been word-wrapped.Solutions below which explode() the text on end-of-lines and wordwrap() the resulting strings separately take care of this nicely.
I've seen a few solutions to the same problem.& Here's a solution to breaking long text with a space.& In this case it breaks after matching 27 characters.$content = preg_replace("/([^\s]{27})/", "$1 ", $content); You can probably write a function for this...
Wordwrap with UTF-8 supports, returns as array.&?phpfunction mb_wordwrap_array($string, $width){& & if (($len = mb_strlen($string, 'UTF-8')) &= $width)& & {& & & & return array($string);& & }& & $return = array();& & $last_space = FALSE;& & $i = 0;& & do& & {& & & & if (mb_substr($string, $i, 1, 'UTF-8') == ' ')& & & & {& & & & & & $last_space = $i;& & & & }& & & & if ($i & $width)& & & & {& & & & & & $last_space = ($last_space == 0) ? $width : $last_space;& & & & & & & & $return[] = trim(mb_substr($string, 0, $last_space, 'UTF-8'));& & & & & & $string = mb_substr($string, $last_space, $len, 'UTF-8');& & & & & & $len = mb_strlen($string, 'UTF-8');& & & & & & $i = 0;& & & & }& & & & $i++;& & }& & while ($i & $len);& & $return[] = trim($string);& & return $return;}?&
If your goal is to allow a browser to word-wrap nicely, while maintaining a fluid layout, you'll want to break with: &#8203It's a zero width space character: This way the browser can break where it needs to, without adding a visual distraction of spaces within the text. e.g.&?php$line = wordwrap($line, 10, "​", true);?&#PROTIP: leave a comment, so the next person to read your code has a clue what you've done.
Here I have come out with a possibly very useful wordwrap code snippet.Apparently what this piece of code does is: it takes the entered text and looks for words longer than the defined ‘$chunk_length’ if it finds any, it splits the long words and then it concatenates the whole string back to a new string with longer words separated by a dash character in this case.After it has accomplished this task it then inserts an HTML line break after a specified ‘$line_length’ (Depending on your containers width requirements)&?phpfunction explode_wrap($text, $chunk_length, $line_length){$string_chunks = explode(' ', $text);foreach ($string_chunks as $chunk =& $value) {if(strlen($value) &= $chunk_length){$new_string_chunks[$chunk] = chunk_split($value, $chunk_length, ' - ');}else {$new_string_chunks[$chunk] = $value;}}$new_text=implode(' ', $new_string_chunks);return wordwrap($new_text, $line_length, '&br /&');}?&
If you need a function to cut only words longer than N characters, feel free to use the function below:
&?php
function wrap($str, $width=75, $break="\n") {
& return preg_replace('#(\S{'.$width.',})#e', "chunk_split('$1', ".$width.", '".$break."')", $str);
}
echo wrap('aaaa bbb cc dddd-dddd', 3, ' ');
?&
The above example will output: "aaa a& bbb& cc ddd d-d ddd "
After I got some problems with my function to convert a BB-text into HTML. Long words didn't really fit into the layout and only wordwarp() also added breaks to words which would fit into the layout or destroy the other HTML-tags....So this is my solution. Only words with strlen() &= 40 are edited with wordwarp().&?phpfunction bb2html($bb) {& & & & $words= explode(' ', $bb); foreach ($words as $word) {& & & & $break = 0;& & & & for ($i = 0; $i & strlen($word); $i++) {& & & & & & if ($break &= 40) {& & & & & & & & $word= wordwrap($word, 40, '-&br&', true); $break = 0;& & & & & & }& & & & & & $break++;& & & & }& & & & $newText[] = $word; }& & $bb = implode(' ', $newText); return $bb;}?&
My version of multibyte wordwrap&?phpfunction mb_wordwrap($string, $width=75, $break="\n", $cut = false) {& & if (!$cut) {& & & & $regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U';& & } else {& & & & $regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';& & }& & $string_length = mb_strlen($string,'UTF-8');& & $cut_length = ceil($string_length / $width);& & $i = 1;& & $return = '';& & while ($i & $cut_length) {& & & & preg_match($regexp, $string,$matches);& & & & $new_string = $matches[0];& & & & $return .= $new_string.$break;& & & & $string = substr($string, strlen($new_string));& & & & $i++;& & }& & return $return.$string;}$mb_string = "こんにちは";$cut_mb_string = mb_wordwrap($mb_string,1," ",true); print($cut_mb_string);?&}

我要回帖

更多关于 qpi wrap card是什么 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信