Functions to reverse a string in Python and PHP