Re: Uppercase first letter of each new line?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx> wrote in message news:1204147905.18306.1256.camel@xxxxxxxxxx

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.          |
`------------------------------------------------------------'

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux