You are here: Re: [PHP] sentence case « PHP « IT news, forums, messages
Re: [PHP] sentence case

Posted by Mattias Thorslund on 02/23/05 21:03

Chris W. Parker wrote:

>Leif Gregory <mailto:Leifg@doh.state.nm.us>
> on Wednesday, February 23, 2005 10:31 AM said:
>
>
>
>>I'm thinking something like:
>>
>>1. strtolower() the string
>>2. explode() on the period
>>3. Loop through the resulting array
>> a. trim() whitespace on each element
>> b. ucfirst() on each element of the array
>> c. Concatenate the string back together, putting a period and a
>> space at the end of each element.
>>
>>
>
>And on top of that he'll need to convert all 'i' to 'I' because of step
>1.
>
>
.... and to be really picky, convert common acronyms to upper-case as
well. :-)

That chould be done with str_replace and arrays for 'find' and 'replace'
- the challenge is to come up with the list of acronyms...

$find = array('stfu', 'rtfm', 'lol');
$replace = array('STFU', 'RTFM', 'LOL');

$replaced_string = str_replace($find, $replace, $old_string);

Of course, se notice that the content of $replace is the same as $find,
but upper-cased. Is there a more elegant solution?

/Mattas

--
More views at http://www.thorslund.us

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация