SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: capitalize

  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    capitalize

    maybe a very easy question...

    How do I change the first letter of a word into a Capital letter using PHP?

    Say the variable is filled with 'dog', how do I change it to 'Dog'?

    And another question:

    How do I limit the number of characters in a variable?

    Say the variable is 'The Institutionalization of Third World Countries' and I want to limit the maximum number of character in the variable to 28.
    How do I limit the variable and end it with '...'

    In my example:
    'The Institutionalization of...'

    Any help would be appreciated!

    Jazz

  2. #2
    SitePoint Member
    Join Date
    Sep 2001
    Location
    Maryland
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First question, use the function ucfirst() like:
    $text = ucfirst($text);
    if the entire string is uppercase, nothing will happen, you may want to use:
    $text = ucfirst(strtolower($text));

    Second question, I don't know of any way to limit the number of characters that can be put into a variable, but once they are in you could use something like:
    $text = substr($text,0,26);

    HTH

    Kevin

  3. #3
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $text = substr($text,0,26);
    to append your '...' merele make this

    PHP Code:
    $text substr($text,0,26).'...'
    aaron
    signature

  4. #4
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx Aaron and Kevin!

    That helped a lot

    Jazz


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
  •