Replaced all invocations to strlen and substr (Fix #6)

This modifications are to make the library compatible with environments in which php has been configured to override string functions with the correspondent mb_string ones (i.e. to force the internal encoding to UTF-8).