Re: Uppercase first letter of each new line?

From: Date: Wed, 27 Feb 2008 21:38:44 +0000
Subject: Re: Uppercase first letter of each new line?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-270432@lists.php.net to get a copy of this message
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" <robert@interjinn.com> wrote in message news:1204147905.18306.1256.camel@blobule...
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";
<?php 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.          |
`------------------------------------------------------------' 


« previous php.general (#270432) next »