/    Sign up×
Community /Pin to ProfileBookmark

How to set lower text and first character as CAPS?

I have code like:

[code=php]

foreach($var as $i=>$element) {
$var[$i] = ucfirst($element);
}

[/code]

Issue is that exploded text is all the time CAPS like
TEXT

When I try to ucfirst it will be not Text as all are CAPS.

PHP:
Returns a string with the first character of str capitalized, if that character is alphabetic.

If I try $var[$i] = mb_strtolower($element); it will be all lower.

How to set in one line mb_strtolower and the first character capitalized like Text?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 13.2011 — [code=php]
$text = ucfirst(strtolower($text));
[/code]


However, you might not like this if $text contains proper names which should be capitalized, or more than one sentence, or acronyms, or anything else that would require a capitalized letter in the middle of the string.
Copy linkTweet thisAlerts:
@toplisekauthorMay 13.2011 — [code=php]
$text = ucfirst(strtolower($text));
[/code]
[/QUOTE]


I have tested many possibilities.

It works $var[$i] = mb_convert_case(mb_strtolower($element), MB_CASE_TITLE);

But still is issue UTF-8 encoding. How to work some special characters like č.

It shows me �

I worked some other function mb_strtolower($variable, 'UTF-8'))

How to set UTF-8 inside:

$var[$i] = mb_convert_case(mb_strtolower($element), MB_CASE_TITLE);
×

Success!

Help @toplisek 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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