SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    lower case first letter of every word

    How can I make the first letter of each word lowercase in a string with a lower version than PHP 5.3?

    I can do it, but only with lcfirst (PHP 5 >= 5.3.0)

    PHP Code:
    function lcallfirst($string)
    {
    $string=explode(" ",$string);
    $i=0;
    while(
    $i<count($string))
    {
    $string[$i]=lcfirst($string[$i]);
    $i++;}
    return 
    implode(" ",$string);

    Last edited by ScallioXTX; Feb 23, 2011 at 18:25. Reason: changes question as per post #4

  2. #2
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    989
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lcfirst is opposite of capitalize - it turns first letter into lower case, not upper case
    Capitalize usually done like this ucwords(strtolower($str));
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    * wrong question, sorry.
    goal is to do the opposite, is putting the first letter in lowercase only!

    can any admin edit the title and change the question? it will be confusing to people who are reading it. many thanks

  5. #5
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to lower case first letter of every word? What about the other letters? Should other be left unchanged?
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, left unchanged

  7. #7
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    function lcwords($str)
    {
        return preg_replace('#\b([a-z])#ie', "strtolower($1)", $str);
    }
    aaron-fisher.com - PHP articles and more


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
  •