Re: slicing and dicing strings

From: Date: Thu, 28 Jun 2012 17:08:31 +0000
Subject: Re: slicing and dicing strings
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-318329@lists.php.net to get a copy of this message
On Wed, Jun 27, 2012 at 6:15 PM, Kirk Bailey <kbailey@howlermonkey.net> wrote: > ok, it slices and dices, but how? > in python, to print all but the last char in string FOO, we say > print FOO[:-1] > But this seems to bark like a basset hound in php. Whyfore? It is a longer syntax which, in agreement with some folks, I think could be shortened (there's a feature request you could submit if you were so inclined), but there's a few methods you could use. Two of which are shown below. <?php $foo = 'This seems to bark like a basset hound in PHP'; echo $foo{(strlen($foo) - 1)}; echo substr($foo,-1); ?> -- </Daniel P. Brown> Network Infrastructure Manager http://www.php.net/

« previous php.general (#318329) next »