Is there a way for me to return the first character in a string.
For example:
$string = "poop"; $fchar = first_char($string); echo $fchar;
The output would be "p" Is there a function like this? (It would be nice) Or am I going to have to convert the string into an array and print out $array[0]?
A string is already an array, so $string[0] will give you what you want.
$first_char = substr($string, 0, 1); Happy if it helps you! bye
Basically this is true... but it WILL generate a non-fatal error. (default not shown)
substr($string,0,1) is a wiser solution.
especially if the string contains for example:
$string="4"; if you'd use $string[0] on this string you'd get an error.
Because you posted this in a database forum, I could guess you're trying to get the value from a database.
A good query string in mysql to do this is to use the ascii(column) funtion where the function returns the ascii value of the first character in the string.