Adding a useful function from he php docs.