SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: UCFirst Problem

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    UCFirst Problem

    I am trying to use ucfirst on my variable:

    $subject = ucfirst($_POST['subject']);

    it dosnt seem to work properly for example:
    I type test it outputs to Test - which is fine.
    I type tEsT and it outputs as TEsT.

    how can I change it so no matter what I type it outputs the first letter as a capital and the rest lowercase?
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,215
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $subject ucfirst(strtolower($_POST['subject'])); 

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,880
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Just in case the title has more than one word:

    // From the manual: "http://www.php.net/manual/en/function.ucwords.php"
    PHP Code:
    <?php
    echo '<br />'
      
    $bar 'what is the meaning of life?';  // what is the meaning of life?

    echo '<br />'
      
    $bar strtoupper($bar);                // WHAT IS THE MEANING OF LIFE?

    echo '<br />'
      
    $bar ucwords($bar);                   // WHAT IS THE MEANING OF LIFE?

    echo '<br />'
      
    $bar ucwords(strtolower($bar));   // What Is The Meaning Of Life?

    ?>
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  4. #4
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys.
    Animated Chatrooms - www.121chatrooms.net


Bookmarks

Posting Permissions

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