Well stop before you rewrite it.
http://phpjs.org/ Has been a great fill in for all those times I just wished I had access to the 1M+ functions php seems to have.
I like to wrap it all in an object so I can access something like: php.explode(',', someString);
For want of a nail the shoe was lost. For want of a shoe the horse was lost. For want of a horse the rider was lost. For want of a rider the battle was lost. For want of a battle the kingdom was lost. And all for the want of a horseshoe nail.
Functions overview - php.js