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
:
// singlebyte strings
$result = substr($myStr, 0, 5);
// multibyte strings
$result = mb_substr($myStr, 0, 5);
More Related Contents:
- How do I check if a string contains a specific word?
- How to get a substring between two strings in PHP?
- Making sure PHP substr finishes on a word not a character
- How to select first 10 words of a sentence?
- PHP substring extraction. Get the string before the first ‘/’ or the whole string
- Getting the first character of a string with $str[0]
- How to separate letters and digits from a string in php
- Check if variable starts with ‘http’
- Remove everything from the first occurrence of a character to the end of a string in PHP
- What is the fastest way to find the occurrence of a string in another string? [duplicate]
- PHP DateTime supported formats
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE `id` [closed]
- How to extract and access data from JSON with PHP?
- PHP validation/regex for URL
- continue processing php after sending http response
- How to write into a file in PHP?
- PHP: Merge 2 Multidimensional Arrays
- “[notice] child pid XXXX exit signal Segmentation fault (11)” in apache error.log [closed]
- Symfony2 – creating own vendor bundle – project and git strategy
- How can I set cron job through PHP script
- Why shouldn’t I use PHP’s mail() function?
- Find common values in multiple arrays with PHP
- Laravel nested relationships
- Laravel 5.2 not reading env file
- PHP – Check if the page run on Mobile or Desktop browser [duplicate]
- Dynamic Table Generation
- str_replace with array
- Laravel validation attributes “nice names”
- Array size limit in PHP
- PHP – GetSQLValueString function