PHP functions in Javascript using PHP.JS
PHP.JS is an open source project started by which aims at providing the standard PHP functions for Javascript development. This eases up programming in Javascript for PHP developers as they can use functions they are familiar with. Currently the project has ported around 230+ PHP functions.
To use this library all you need to do is to download the php.js file and include it in your page:
<script src="/pathto/php.js"></script> |
Then use use the function as you would in PHP. For example if you want to use the urlencode function in Javascript, just use it like this in Javascript
urlencode('http://blogs.vinuthomas.com/'); |
This should return ‘http%3A%2F%2Fblogs.vinuthomas.com%2F’. As easy as that !
Edit: As Kevin mentioned in the comments below, don’t use the entire php.js file in your projects, just use the function you need.
History of PHP.JS from (phpjs.org):
A developer called Kevin van Zonneveld was once working on a project with a lot of client(JS) / server(PHP) interaction, and he found himself coding PHP functions (like base64_decode & urldecode) in JavaScript to smoothen communication between the two languages.
He stored the stored the functions in a file called php.js which was included in the project. But even when the project was done, it remained fun trying to port PHP functions to JavaScript and so the library grew.
Kevin decided to share the little library online, which triggered the enthusiasm of a lot of PHP developers longing for PHP functionality in JavaScript. The project was open sourced in 2008, and many people contributed their own functions in the comments sections of Kevin’s blog.
It was decided that the library deserved a bigger home, and a face of its own, and so the PHP.JS core team (which at that time also consisted of Michael White, Felix Geisendörfer, Philip Peterson) developed the phpjs.org website
Links:
PHP.JS Home Page
List of Functions available in PHP.JS
Download PHP.JS
|