Re: slicing and dicing strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 27, 2012 at 6:15 PM, Kirk Bailey <kbailey@xxxxxxxxxxxxxxxx> 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/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux