RE: [PHP] Uppercase first letter of each new line?
> -Original Message- > From: M. Sokolewicz [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 27, 2008 6:06 PM > To: Daniel Brown > Cc: Robert Cummings; Keikonium; php-general@lists.php.net > Subject: Re: [PHP] Uppercase first letter of each new line? > > Daniel Brown wrote: > > On Wed, Feb 27, 2008 at 5:08 PM, Robert Cummings <[EMAIL PROTECTED]> > wrote: > >> On Wed, 2008-02-27 at 16:38 -0500, Keikonium wrote: > >> > Thank you again Robert, and thank you too Daniel. I have gotten both > methods > >> > to work flawlessly so far :). I am slowly learning by trial and error > here, > >> > but sometimes a little push in the right direction does some good > ^_^. > >> > >> Nothing against Dan, but you should use my version if this is coming > >> from browser submitted data. Dan's presumes unix lines endings which > >> won't always be the case. > > > > Well, actually, my code will still split it properly (the \n is > > still at the end), but the \r will become part of the string. Then, > > when it's modified and passed back with the \n appended, it is redone > > as \r\n. > > > > In any case, as I already said in a previous message, I still > > agree. Use Rob's code. > > > And what happens if someone uses a(n old) Mac? Where it's just \r (no \n > at all) :) > > - Tul I must declare myself ignorant on this issue, but if you are telling us that only an old Mac will send you line feeds alone... I'd say you have more browser related problems than just new lines. We don't target IE 4 anymore do we? (I don't even target IE 5, it's not worth the pain). Again, my experience with the Mac world is nearly zero. I don't know which specific OS+Browser would cause the issue, but if it is only an old Mac with an old browser... well, I wouldn't care, as I don't care if a visitor with Windows 98+IE5 can't handle CSS and/or Javascript properly. You have to set a limit somewhere (otherwise, why don't we use HTML 3.2 and that's it?). Mine is at IE 6+ and latest FF/Opera/Safari. For the webs I develop, that's more than enough (it covers more than 90% of the market). Anyway... I'm just blind ignorant of what is the specific Mac OS and browser that can cause you trouble with line feeds (maybe all of them has this behavior, I repeat, I don't know). Regards, Rob(inet) Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 | TEL 954-607-4207 | FAX 954-337-2695 | Email: [EMAIL PROTECTED] | MSN Chat: [EMAIL PROTECTED] | SKYPE: bestplace | Web: bestplace.biz | Web: seo-diy.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, Feb 27, 2008 at 6:05 PM, M. Sokolewicz <[EMAIL PROTECTED]> wrote: > And what happens if someone uses a(n old) Mac? Where it's just \r (no \n > at all) :) A very good point! Anyone who may be accessing the page and sending data from a pre-OS9 system, an Apple IIe (or any Apple II), or a Commodore, should be pushed through Rob's regexp without question. And so I reiterate: agreed. ;-P -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
Daniel Brown wrote: On Wed, Feb 27, 2008 at 5:08 PM, Robert Cummings <[EMAIL PROTECTED]> wrote: On Wed, 2008-02-27 at 16:38 -0500, Keikonium wrote: > Thank you again Robert, and thank you too Daniel. I have gotten both methods > to work flawlessly so far :). I am slowly learning by trial and error here, > but sometimes a little push in the right direction does some good ^_^. Nothing against Dan, but you should use my version if this is coming from browser submitted data. Dan's presumes unix lines endings which won't always be the case. Well, actually, my code will still split it properly (the \n is still at the end), but the \r will become part of the string. Then, when it's modified and passed back with the \n appended, it is redone as \r\n. In any case, as I already said in a previous message, I still agree. Use Rob's code. And what happens if someone uses a(n old) Mac? Where it's just \r (no \n at all) :) - Tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, Feb 27, 2008 at 5:08 PM, Robert Cummings <[EMAIL PROTECTED]> wrote: > > On Wed, 2008-02-27 at 16:38 -0500, Keikonium wrote: > > Thank you again Robert, and thank you too Daniel. I have gotten both > methods > > to work flawlessly so far :). I am slowly learning by trial and error here, > > but sometimes a little push in the right direction does some good ^_^. > > Nothing against Dan, but you should use my version if this is coming > from browser submitted data. Dan's presumes unix lines endings which > won't always be the case. Well, actually, my code will still split it properly (the \n is still at the end), but the \r will become part of the string. Then, when it's modified and passed back with the \n appended, it is redone as \r\n. In any case, as I already said in a previous message, I still agree. Use Rob's code. -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Uppercase first letter of each new line?
> -Original Message- > From: Robert Cummings [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 27, 2008 5:09 PM > To: Keikonium > Cc: php-general@lists.php.net > Subject: Re: [PHP] Uppercase first letter of each new line? > > > On Wed, 2008-02-27 at 16:38 -0500, Keikonium wrote: > > Thank you again Robert, and thank you too Daniel. I have gotten both > methods > > to work flawlessly so far :). I am slowly learning by trial and error > here, > > but sometimes a little push in the right direction does some good ^_^. > > Nothing against Dan, but you should use my version if this is coming > from browser submitted data. Dan's presumes unix lines endings which > won't always be the case. > > Cheers, > Rob. > -- > .. > | InterJinn Application Framework - http://www.interjinn.com | > :: > | An application and templating framework for PHP. Boasting | > | a powerful, scalable system for accessing system services | > | such as forms, properties, sessions, and caches. InterJinn | > | also provides an extremely flexible architecture for | > | creating re-usable components quickly and easily. | > `' > > -- Unless you only get line feeds ("\r"), this should work as well (for "\n" or "\r\n" as line separators) $text = getTextFromSomewhereElse(); $newText = join("\n", array_map('ucfirst', explode("\n", $text))); (fist thing that came to my mind, just posting because of that... use the regex if you want to be safe) Regards, Rob(inet) Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 | TEL 954-607-4207 | FAX 954-337-2695 | Email: [EMAIL PROTECTED] | MSN Chat: [EMAIL PROTECTED] | SKYPE: bestplace | Web: bestplace.biz | Web: seo-diy.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, Feb 27, 2008 at 5:08 PM, Robert Cummings <[EMAIL PROTECTED]> wrote: > > On Wed, 2008-02-27 at 16:38 -0500, Keikonium wrote: > > Thank you again Robert, and thank you too Daniel. I have gotten both > methods > > to work flawlessly so far :). I am slowly learning by trial and error here, > > but sometimes a little push in the right direction does some good ^_^. > > Nothing against Dan, but you should use my version if this is coming > from browser submitted data. Dan's presumes unix lines endings which > won't always be the case. Agreed! -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, 2008-02-27 at 16:38 -0500, Keikonium wrote: > Thank you again Robert, and thank you too Daniel. I have gotten both methods > to work flawlessly so far :). I am slowly learning by trial and error here, > but sometimes a little push in the right direction does some good ^_^. Nothing against Dan, but you should use my version if this is coming from browser submitted data. Dan's presumes unix lines endings which won't always be the case. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
Thank you again Robert, and thank you too Daniel. I have gotten both methods to work flawlessly so far :). I am slowly learning by trial and error here, but sometimes a little push in the right direction does some good ^_^. Thanks again :). "Robert Cummings" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Wed, 2008-02-27 at 16:24 -0500, Robert Cummings wrote: On Wed, 2008-02-27 at 16:13 -0500, Keikonium wrote: > I'm sure this is really easy to accomplish, but I just can't seem to > figure > it out. I have the following: > > $str = " > mary had a little lamb > it's fleece was white as snow > and everywhere that mary went > the lamb was sure to go"; Actually, the regex is slightly more complex if you want to cover different carriage return / newline orderings and also catch the case where the text doesn't begin with a newline... $str = preg_replace_callback( '/(^|([\n\r]+))[^\n\r]/ms', 'ucCallback', $str ); Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, 2008-02-27 at 16:24 -0500, Robert Cummings wrote: > On Wed, 2008-02-27 at 16:13 -0500, Keikonium wrote: > > I'm sure this is really easy to accomplish, but I just can't seem to figure > > it out. I have the following: > > > > $str = " > > mary had a little lamb > > it's fleece was white as snow > > and everywhere that mary went > > the lamb was sure to go"; > > > function ucCallback( $match ) > { > return strtoupper( $match[0] ); > } > > $str = " > mary had a little lamb > it's fleece was white as snow > and everywhere that mary went > the lamb was sure to go"; > > echo $str."\n\n"; > > $str = preg_replace_callback( '/\n\r?./ms', 'ucCallback', $str ); Actually, the regex is slightly more complex if you want to cover different carriage return / newline orderings and also catch the case where the text doesn't begin with a newline... $str = preg_replace_callback( '/(^|([\n\r]+))[^\n\r]/ms', 'ucCallback', $str ); Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, 2008-02-27 at 16:13 -0500, Keikonium wrote: > I'm sure this is really easy to accomplish, but I just can't seem to figure > it out. I have the following: > > $str = " > mary had a little lamb > it's fleece was white as snow > and everywhere that mary went > the lamb was sure to go"; Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Uppercase first letter of each new line?
On Wed, Feb 27, 2008 at 4:13 PM, Keikonium <[EMAIL PROTECTED]> wrote: [snip!] > I was thinking something like splitting each new line into a separate > string, capitalizing the first letter with ucfirst(), and then merging the > string back together might work, but I am not sure how to find a new line. [snip!] Here's a function to help you out. It's also online here: [Demo]http://www.pilotpig.net/code-library/capitalize-line.php [Source] http://www.pilotpig.net/code-library/source.php?f=capitalize-line.php function ucnewline($str) { $arr = explode("\n",$str); foreach($arr as $p) { $ret .= ucfirst($p)."\n"; } return $ret; } -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Uppercase first letter of each new line?
I'm sure this is really easy to accomplish, but I just can't seem to figure it out. I have the following: $str = " mary had a little lamb it's fleece was white as snow and everywhere that mary went the lamb was sure to go"; Using ucfirst($str) will only capitalize the first letter of the string (duh :P). So I tried ucwords($str) and it obviously capitalized EVERY word. Also not desired. I couldn't find a php function to capitalize each new line, so I was thinking that regex would probably be needed and I am just no good at that @[EMAIL PROTECTED] I was reading up about it a bit, but it's still really confusing me. I was thinking something like splitting each new line into a separate string, capitalizing the first letter with ucfirst(), and then merging the string back together might work, but I am not sure how to find a new line. Any help would be appreciated Thank you in advance :). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php