Results 1 to 3 of 3

Thread: How to set lower text and first character as CAPS?

  1. #1
    Join Date
    Sep 2005

    How to set lower text and first character as CAPS?

    I have code like:
    PHP Code:

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

    Issue is that exploded text is all the time CAPS like

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

    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?

  2. #2
    Join Date
    Aug 2004
    PHP Code:
    $text ucfirst(strtolower($text)); 
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Sep 2005


    Quote Originally Posted by NogDog View Post
    PHP Code:
    $text ucfirst(strtolower($text)); 
    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);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center