PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Wed Jul 21, 2004 7:51 pm
What is the best way to get the capital letters from a string?
ex:
Code: Select all
<?php
$myString = 'HereIsMyStringMcDonald';
echo getCapitalLetters($myString );
//Would return: HIMSMD
function getCapitalLetters($str){
//extract capital letters and return
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jul 21, 2004 7:53 pm
untested Code: Select all
function getCapitalLetters($str)
{
if(preg_match_all('#([A-Z]+)#',$str,$matches))
return implode('',$matches[1]);
else
return false;
}
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Wed Jul 21, 2004 7:58 pm
Works awesome.
Thanks Feyd. I've noticed your typically the first to respond with regular expressions. Is this something you learned programming other languages?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jul 21, 2004 8:02 pm
Not really.. I just have some decent practice with them
They're my kinda language..