📜 ⬆️ ⬇️

JSSamePHP: I know PHP, but I need JavaScript

Theory


Perhaps there are a lot of people like me, fans of syntax and PHP functions, which need to be written, say, in JavaScript, and there is no time to study functions.
Yes, we well know the basic functions of PHP - this is our weapon! And if we also think instead of the native language in PHP - this is our neglected case, for which I began to fill my library, which I called JSSamePHP (JS as PHP).
Understandable language - analogues of PHP functions in JavaScript.

Practice


I will not bore you with boring manuals on how to connect the JS library, but go straight to the point: we connect our JSSamePHP, after jQuery, because it is completely possible that we will use its capabilities, as in the trim () function. Yes, you can write everything in pure JavaScript, but here is a matter of personal preference.

A small example of JSSamePHP.js script code:
function strlen(str){return str.length;} function count(str){return str.count;} function trim(str){return $.trim(str);} function explode(a,b){return b.split(a);} function substr(a,b,c){if(b<0){b+=a.length;}if(c==undefined){c=a.length;}else if(c<0){c+=a.length;}else{c+=b;}if(c<b){c=b;}return a.substring(b,c);} function str_replace(a,b,c){return c.replace(a,b);} function is_numeric(a){return !isNaN(a-0) && a!==null && a.replace(/^\s\s*/,'')!=="" && a!==false;} 

I save, yes, that does not take away.

As you can see from the function names - now we can engage in an unequal battle with JavaScript without using such weapons as tutorials and cheat sheets, always remembering how it works in PHP. Believe me, the speed of writing code, without wasting extra time on memories, “how is it in JS” will increase dramatically.
')
Well, now a typical example:
 // ,     var STR=' '; var Count=strlen(STR); //   Count = 13 // ,   PHP:   ,      var STR='  '; var Count=strlen(trim(STR)); //   Count = 13,     ,     trim(),   PHP 

Have a good fight, colleagues!

Source: https://habr.com/ru/post/217341/


All Articles