Fw: [PHP] Looking at individual chars of string

From: Date: Mon, 17 Mar 2003 19:10:22 +0000
Subject: Fw: [PHP] Looking at individual chars of string
Groups: php.general 
Request: Send a blank email to php-general+get-140004@lists.php.net to get a copy of this message
----- Original Message ----- From: "Bix" <php@bix.cc> To: <php-general@lists.php.net> Sent: Monday, March 17, 2003 12:04 PM Subject: [PHP] Looking at individual chars of string > Is it possible to look at individual chars of a string? > > eg: $str = "12345"; > > print $str_1 // Gives "1" > print $str_2 // Gives "2" > > Doing this with an array would be handy, maybe using explode or preg_split? > > Thanks in advance! Actually as far as the computer knows strings *are* arrays. Access any character within a string in the same mannor as you would access an element in an array. For example: $str = "hello world"; echo $str[4]; // prints o echo $str[6]; // prints w HTH, Kevin

« previous php.general (#140004) next »