Re: slicing and dicing strings
| From: | Shailesh N. Humbad | Date: | Thu, 28 Jun 2012 12:44:52 +0000 |
| Subject: | Re: slicing and dicing strings | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318326@lists.php.net to get a copy of this message | ||
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: http://www.php.net/manual/en/function.substr.php