Jump to content


string formatting-help

  • Please log in to reply
2 replies to this topic

#1 natalieG

  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 25 June 2006 - 03:45 PM

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);

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 June 2006 - 07:13 PM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 June 2006 - 10:24 AM

wicked burn!
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users