Jump to content


This topic is now archived and is closed to further replies.


string formatting-help

Recommended Posts

wer posted a question the other day about code to word wrap long string into several lines, separated
by 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.



function abc($instr){
return trim(preg_replace('/\s+/',' ',$instr));
$xyz= '345 Penninsuoa St olttown tommorrow any state usa ghg vbgv';
//eliminate multiple spaces with reg_replace spaces

function addressformat($add1,$line){
//remove multiple white spaces and concert to array..
$add1array=explode(' ',$add1);
foreach($add1array as $str){
#$len2=$len2 + $str_len;
#print "$len/$len2<BR>";
if ($len>=$line){$len=$str_len;$out="<BR>" . $out . ' ' . $str;}
else{$out=$out .' ' . $str;}
return $out;
print "<P>";
print addressformat($xyz2,30);

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.