Generic filters
Exact matches only
  • Take off / Get first 5 characters (substr)

    10th February 2014

    Php - Strings

    php codehaven

    This gets the first 5 characters of a string
    ‘Monday’ Becomes ‘Monda’
    and ‘saturday’ Becomes ‘satur’

    For single-byte strings (e.g. US-ASCII, ISO 8859 family, etc.) use substr and for multi-byte strings (e.g. UTF-8, UTF-16, etc.) use mb_substr:

    Below starts from the third character

    The above result would be 12345

    Was this code snippet helpful?