3Answer
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);
- answered 8 years ago
- Community wiki
If you want to get only one character then use.
$str = 'abcdefghij';
echo $str{5};
- answered 8 years ago
- Community wiki
Your Answer