natalieG Posted June 25, 2006 Share Posted June 25, 2006 wer posted a question the other day about code to word wrap long string into several lines, separatedby a <BR>. WE did get an answer, but that we want is to only break at word boundaries, so we were probably not clear about the breakl criteria. We wrote an example, but we never see get the line breakl, even though the sting was longer than the word wrap boundary. Our code is below. Hope yopu can help us.Thnanks,Jennifer<?phpfunction abc($instr){return trim(preg_replace('/\s+/',' ',$instr));}//abc$xyz= '345 Penninsuoa St olttown tommorrow any state usa ghg vbgv';//eliminate multiple spaces with reg_replace spaces$xyz2=abc($xyz);function addressformat($add1,$line){$len=0;$len2=0;$out='';//remove multiple white spaces and concert to array..$add1array=explode(' ',$add1); foreach($add1array as $str){ $str_len=strlen($str); $len=$len+$str_len; #$len2=$len2 + $str_len; #print "$len/$len2<BR>"; if ($len>=$line){$len=$str_len;$out="<BR>" . $out . ' ' . $str;} else{$out=$out .' ' . $str;} }//foreach return $out; }//addrressformat.. print "<P>"; print addressformat($xyz2,30);?> Quote Link to comment https://forums.phpfreaks.com/topic/12870-string-formatting-help/ Share on other sites More sharing options...
Barand Posted June 25, 2006 Share Posted June 25, 2006 Here's an example of breaking up strings on word boundaries only.[a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=96751&view=findpost&p=387586\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=387586[/a]And guess what, it's a reply to your previous topic. If you ain't going to read them, why should we bother to reply? Quote Link to comment https://forums.phpfreaks.com/topic/12870-string-formatting-help/#findComment-49428 Share on other sites More sharing options...
.josh Posted June 26, 2006 Share Posted June 26, 2006 wicked burn! Quote Link to comment https://forums.phpfreaks.com/topic/12870-string-formatting-help/#findComment-49612 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.