0

What is the correct syntax for selecting the first letter in a string? In php

I've tried [0] but have been told it's wrong?

14th Jun 2017, 10:17 PM
David Mason
David Mason - avatar
3 Answers
+ 4
14th Jun 2017, 11:38 PM
Hasan Misbah
Hasan Misbah - avatar
+ 2
have you tried for loop?
14th Jun 2017, 11:13 PM
Hasan Misbah
Hasan Misbah - avatar
+ 1
$myString = "Hello"; $first = $myString[0]; // This actually gets the first Byte not necessarily the character $first = subset($myString, 0, 1) // Again gets the first Byte These may have issues when the the encoding character type, like UTF-8, is multibyte. So use: $first = mb_substr($myString, 0, 1, 'utf-8'); http://php.net/manual/en/function.mb-substr.php
14th Jun 2017, 11:45 PM
ChaoticDawg
ChaoticDawg - avatar