Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2008
    Posts
    119
    Tokens
    0

    Default Limit ammount of characters with php?

    Im trying to limit a string to 10 characters, but i can't work out how to do it. Ive tried string pad but it can only be used to make the string bigger;

    $shorten = "hihihihihihihihihihiihhihihihihihihih";
    $shorten = str_pad ( $shorten, 10 );
    echo $shorten

    That just echos "hihihihihihihihihihiihhihihihihihihih". Is there any function to shrink a string?
    Signature Removed by Jamesy (Forum Super Moderator): Referal

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Hi,

    You could use the function substr.

    For example:

    PHP Code:

    $wat 
    "thisstringisover10characters";
    $wat substr$wat010 );

    echo 
    $wat// outputs: thisstring 
    Thanks,
    Invent

  3. #3
    Join Date
    Jul 2008
    Posts
    119
    Tokens
    0

    Default

    Thats exactly what i was looking for, Thanks I will +rep you when i get my other account back.
    Signature Removed by Jamesy (Forum Super Moderator): Referal

  4. #4
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Hi,

    Good to hear thats what you needed

    Thanks,
    Invent

Posting Permissions

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