Re: Uppercase first letter of each new line?

From: Date: Wed, 27 Feb 2008 21:31:45 +0000
Subject: Re: Uppercase first letter of each new line?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-270426@lists.php.net to get a copy of this message
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 (#270426) next »