On 6/27/2012 6:15 PM, Kirk Bailey 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?

Now tihs tyro is seeking sage words to help me understand this.
RTFM is not sage words; if you don't want to help me please don't waste
the bandwidth.

Would anyone care to help me understand this without dedicating 4
precious and in over demand/under supply hours to RTFM?

print substr($foo, 0, -1);

You could also do this, but it takes more code:
print substr($foo, 0, strlen($foo) - 1);

You could wrap it as a function like so:
function strchop($string, $num_chars_to_chop_off_end)
        return substr($string, 0, -$num_chars_to_chop_off_end);

If you have time, the relevant manual page is:

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

Reply via email to