Posted on 2006-04-18
Last Modified: 2006-11-18

I'm looking for the function to get the first x_number of characters from a string...

For example:

The string "This string of text is a little bit too long." should be displayed as:
"This string of text is..."
Question by:Julian Matz
    LVL 54

    Accepted Solution


    You can use substr.  An example would be substr(str, 0, x) where str is the string and x is an integer for the number of character.

    str = "abcdef"
    smallstr = substr(str, 0, 3)

    smallstr would equal abc.

    LVL 21

    Author Comment

    by:Julian Matz
    Hi b0lsc0tt,

    Thank you for the quick answer! Exactly what I was looking for but had trouble finding it in the manual...

    LVL 54

    Expert Comment


    Glad I could help.  Thanks for the fun question, grade and points.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now