One way to find the first character of a string in PHP is to use the substr()
function with an index of 0. Here's an example:
main.php88 chars4 lines
In this code, we define a string $str
and use the substr()
function to get the first character. The first argument to substr()
is the string itself, the second argument is the starting index (0 in this case), and the third argument is the length of the substring we want to extract (which is 1 since we only want one character).
We then assign the result to the variable $firstChar
and use echo
to output the first character, which is "H" in this case.
gistlibby LogSnag