Re: String to an Array

From: Date: Sun, 08 Dec 2002 02:17:11 +0000
Subject: Re: String to an Array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-127411@lists.php.net to get a copy of this message
At 11:15 AM 12/8/02 +1100, Justin French wrote:
I *think* either: <? $str = "im the one trying to do this"; echo $str[0]; ?> OR <? $str = "im the one trying to do this"; echo $str{0}; ?> Works -- you'll have to experiment, but I believe the second way is correct, and will echo the first (0th) character in the string.
This depends on PHP version. In the bad old days you had to use $str[0]. Sometime since PHP4 came out they added the preferred $str{0} option, which is the only one that should be used in new code. Extracting characters from a string with [] is depreciated, and may stop working someday. Rick

« previous php.general (#127411) next »