/    Sign up×
Community /Pin to ProfileBookmark

I made this script to turn the first letter into a capital:

[code=php]function H($text){
return strtoupper(substr($text,0,1)).substr($text,1,strlen($text));
}[/code]

[i]H(text)[/i]will return[i]Text[/i]

I’d like to update my script so that you can insert a longer text, but that doesn’t work.
[i]H(the anime king)[/i] will return [i]The anime king[/i] but I want it to upper all first letters (so it returns [i]The Anime King[/i]).

How can I do that? Thanx!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@mikkoMar 18.2005 — Does it have to be php? :p

You could handle that lot faster with a bit of css...

text-transform: capitalize;


[B]Edit:[/B]

Thought I'd offer a PHP solution as well...

[code=php]function capitalize($text = '') {

$words = explode(' ', $text);
foreach ($words as $word) {
$capitalized[] = strtoupper(substr($word, 0,1)) . substr($word, 1, strlen($word));
}
return implode(' ', $capitalized);

}[/code]



okay... [b]Edit again.[/b]

Feel a bit silly, I should always check PHP.net before trying anything on my own

http://uk2.php.net/manual/en/function.ucwords.php
×

Success!

Help @The_Anime_King spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...