Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the first character of a string

Status
Not open for further replies.

theoneweasel77

Programmer
Aug 10, 2004
54
0
0
US
How would one get the first character of a string, regardless of what it is? I've looked through the PHP manual briefly and nothing looked obvious.
ex. $string = "somestring";
$string = somefunction($string); // returns "s
 
This one's easy!

[tt]$string = substr($string, 0, 1);[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Code:
<?php
$string = 'asdf';
print $string[0];
print $string{0};
print substr( $string, 0, 1 );
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top