Re: stupid identation prob

From: Date: Tue, 26 Dec 2000 21:49:47 +0000
Subject: Re: stupid identation prob
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31883@lists.php.net to get a copy of this message
Here's how I sometimes pad my mail body and such. Here's an example : $string = 'This is a really long string that I want to email to a friend but also want to alter the width of it for my email so I use function padString to set such a width. It strips extra whitespace too. and returns like this are removed'; $mail_body = padString($string,20); mail("to@a.org","subject","$mail_body","From: from@a.org"); Which will set width to 20. Essentially converting the above to this (the \n's do not show in email but message is padded as such) : This is a really long\n string that I want to\n email to a friend but\n also want to alter the\n width of it for my email\n so I use function padString\n to set such a width.\n It strips extra whitespace\n too and returns like this\n are removed.\n Here's the function, if anyone has tips to "improve" it please let me know. It would be nice to have it a bit "more intelligent" but it works nicely as is. Btw, the suffix is optional and could just as easily be turned into a prefix. <?php function padString($string,$width=0,$suffix='') { $pieces = split('[[:space:]]+',$string); $count = count($pieces); foreach ($pieces as $piece) { $a++; if (isset($tmp)) { $piece = trim($tmp . ' ' . $piece); unset($tmp); } if ( (strlen($piece) >= $width) OR ($a == $count) ) { $new_string .= $piece . $suffix . "\n"; } else { $tmp .= $piece; unset($piece); } } Return $new_string; } ?> Hope that helps, Philip Olson --.sig [ Learning requires a humble attitude. ] [ Will work for Money: http://www.cornado.com/ ] On Tue, 26 Dec 2000, Christian Dechery wrote: > This is kinda of a stupid problem... > > how can I keep my mails from getting the identation?? like this... I have > some code: > > <?php > $var = somefunction(); > $do some code here and bla bla; > for (something) > { > do stuff in here; > bla bla; > } > /* now sending the email */ > mail("someone@isp.com","me@home.com","test mail","body of > email.... /* > (here is my question) */ > ?> > > the email will probably be some large amount of text, and I don't want it > to be huuuuge monster line with tons of \n in my code like this: > > "Hi, Someone\n\nbla bla bla blablabla\n\n bla bla bla > bla\nblablabla\n\nblablablabla\n\nRegards, Me." > > instead I'd like to ident this monster string with the rest of my code... > something like: > > mail("someone@isp.com","me@home.com","test mail","body of > email....\n > lalalalala bla bla bla\n > bla bla bla bla\n\n > bla bla bla bla\n\n > bla bla bla\n\n > Regards, Me"); > > this doesn't works... it gets all tabs and (not it Eudora, since it > converts it to <x-tab> and it actually looks pretty neat) makes the email > real crapy looking... > > does anyone has any ideas??? > > thanks... > > > ____________________________ > . Christian Dechery (lemming) > . http://www.tanamesa.com.br > . Gaita-L Owner / Web Developer > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#31883) next »