how can I take starting two character of a string regardless the string lenght.
You can also access parts of a string as an array: `$string[0]` and `$string[1]` are its first two characters.
Erik
2010-05-19 06:24:02
but only if the original string is two characters or longer. Do this to be safe:$string = strlen($str) > 2 ? substr($str, 0, 2) : $str; (strip only if it's longer than 2 chars)
seanizer
2010-05-19 06:26:07
And if you are using UTF8 or other multibyte encoding, use `mb_substr()`
dev-null-dweller
2010-05-19 06:34:08