Posted by Alex M on May 24, 2009 in
Web Development
I have just had a task which requires making the first word of a string uppercase. I have come up with quite an easy and simple solution and thought I would share it with you.
An example input string might look like “HELLO world. This is a test.” The required output is “Hello world. This is a test.”
Below is a function which will help you achieve this:
function uc_first_word($string) {
$s = explode(’ ‘, $string);
$s[0] = ucfirst(strtolower($s[0]));
$s = implode(’ ‘, $s);
return $s;
}
Now I know this function isn’t full proof, and assumes that the string you are passing it actually contains words. If the first word was a roman numeral for example, this function would not work (ie VI would become Vi).
Usage of this function is quite easy:
$string = uc_first_word(’HELLO world. This is a test.’);
I hope that this might help someone searching for a similar solution.
Tags: explode, implode, PHP, strtolower, ucfirst
Posted by Alex M on Mar 26, 2009 in
Web Development
I had to think about this one for a while, as I was trying to delete an array element which I knew the key of (and there is no array_delete() function).
e.g. $array['something'] = ‘value’;
Turns out deleting the value is easy using the unset() command.
unset($array['something']);
$array['something'] no longer exists. Hope this helps someone else.
Tags: Array, PHP, Unset
Posted by Alex M on Dec 22, 2008 in
Web Development
I’ve been trying to work this one out for ages, but I’ve finally figured it out. I always like to be able to edit my .htaccess files, but seeing as they are hidden files, Transmit FTP would never show them. I always ended up going back to my PC and using CuteFTP Pro.
Turns out there is a simple option to show hidden files such as .htaccess in Transmit FTP. Simply select View -> Show Invisible Files.
So simple! I can’t believe I have missed this option all this time.