Updated the script to use only native PHP functions