fix off-by-one and dodgy use of zend_string API, fixes #6