Laziness is the engine of progress. People are constantly creating things designed to ease their hard share. It was laziness that allowed the rag and mop to turn into a washing robot cleaner. Similar processes occur in the field of computer technology. Instead of being content with programming in machine codes, communicating with the processor through a punch card interface, people began to invent all sorts of keyboards, mice and monitors, as well as programming languages. The latter became more and more high-level. As a result, we have what we have - a far incomplete
list of PL . Having enjoyed all the magnificence of this variety, programmers suddenly began to realize that now they are too lazy to learn all these languages, and they began to dream of uniformity on all platforms. So was born JAVA. Those who were too lazy to teach her, continued to dream and write in JavaScript. Their dreams were heard, and on the other hand node.js appeared. And what should we do now? - thought PHP programmers, enviously looking at someone else's happiness. Rolling up their sleeves, they began to work hard, so the php.js project appeared
Surprisingly, on Habré this noteworthy resource
is mentioned only in passing. Fill this obvious gap.
I'll start by translating the
About page:
About the site
php.js is a website that provides community-generated JavaScript alternatives for PHP functions.
If you want to perform high-level actions on JavaScript platforms such as web browsers, node.js, etc., then you will probably have to sit behind the JS code that combines the low-level functions of the language and build them up until you get something useful like strip_tags (), strtotime (), number_format (), wordwrap () or date ().
')
PHP is a language with many high-level functions, but, despite the fact that they are not always implemented as uniformly as we would like (most often because they repeat the underlying C functions), this language has a huge number of followers who are accustomed to this syntax, so it would be wise to take its API as a basis, at the same time saving yourself from the need to write your own documentation, which in general, we hope, will be able to make our lives a little easier.
On the other hand, appreciating JS for its attractive features, we encourage you to explore them. Never use php.js as an excuse for not wanting to give it time. For the same reason, we do not port the whole PHP language or all of its control structures; we only chose features.
It should be added that, considering porting everything as a definite challenge, we decided to enable and even such low-level PHP functions as strpos, despite the fact that their close analogues (String.indexOf) can exist in JavaScript. In addition to the intellectual challenge for ourselves, such porting opens php.js, both for all sorts of mental exercises, and allows it to serve the purposes of studying JS. Thus, we see ourselves as some great resource, and the developers themselves can decide when it makes sense for them to take something from here. And when not.
Cooperation
For collaboration, we use
github . Comments on the site are for comments only. Please read our
wiki tutorials.
Who uses php.js
Licensing
php.js has a dual license - MIT and GPL. This means that you can use php.js under the terms of either the
MIT license or the
GNU Open License Agreement
(GPL) Version 2. (comparative
analysis of licenses by the author)
The MIT license allows you to use this library in any form that is suitable for you, even in commercial projects, as long as you retain the original license when distributing your product. In fact, you do not even need to disclose your modifications, although it would be highly desirable and, in addition to this, would give you confidence that your changes will not be lost after the upgrade. On the other hand, the GPL license makes this library compatible with other GPL projects.
So, first of all, this project will be useful for developers who are familiar with PHP and its libraries. The overwhelming majority of functions work in the browser, perhaps only mail and fopen for the local file on the client side will return an error (what has been done and what needs to be done is written in detail
here . Volunteers ?!). But even if for some reason you are not familiar with PHP, but use JS in your projects, then this resource will certainly be useful to you, at least from an educational point of view. Do not expect miracles, at the time of this writing, the
library contains only 452 functions, a very distant figure from the entire volume of PHP, but believe me, from which to choose there is.
Each function on the site is provided with detailed comments and examples of use (do not forget about the native
PHP documentation ). To get the source of a specific function, you need to click on the get on github link in the upper right corner of the block with the code. I advise you to immediately take
all the source code to yourself, it will be more convenient. Since the library is very extensive, it makes no sense to combine all these functions into one large file, it will be too heavy. Depending on the needs of a particular project, it is necessary to selectively build a library with the functions you need. It also makes sense to think about wrapping this API in some container in order not to clutter up the global namespace. Well, do not forget about the optimization and compression of the code before sending it to the browser.
Summary you can do the following - php.js is a stable and extensive JS library with good documentation that can simplify / speed up the development of your projects. Since the taste and the color, all the markers are different, then let this tool also appear in your arsenal, you see, when it is useful; or it will just be too lazy to boil a regular titanium bicycle and plan a mahogany crutch.