Jump to content

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.

Thnanks,

Jennifer

<?php
function 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);
?>
Link to comment
https://forums.phpfreaks.com/topic/12870-string-formatting-help/
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?
Link to comment
https://forums.phpfreaks.com/topic/12870-string-formatting-help/#findComment-49428
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.