Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get first n Characters from a given string using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 253
    Comment on it

    Hello Readers! On a given string if you want to take out the first n number of characters from it then PHP offers you 'substr' to get the characters. Consider an example below:-

    Suppose I want to get the first 5 characters from string, $MyString

    $MyString = 'Im printing first 5 characters';
    

    I use the line below

    $GetString = substr($MyString,0,10).'...'`
    
    echo $GetSting;
    

    Output:-

    Im printing p
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: