Wikia

JavaScript Wiki

Brettz9/PHP-JavaScript

83pages on
this wiki
Talk0

This section is intended for preparing a JavaScript library which mimics the API of PHP. This is intended to make it easier for PHP developers to use just one familiar API for functions (albeit relying on JavaScript syntax).

The functions may not mirror the exact behavior as found in PHP--either due to insurmountable differences with JavaScript or due to not having been adequately programmed yet (though please help to improve this).

By relying on the PHP interface, we avoid developing yet another library whose API might be too subject to change (though we could update with new versions of PHP). We will only use PHP names, except where an existing JavaScript function of the same name already exists (e.g., "eval"), in which case we will prepend "php_" to the function name.

For I/O and other privileged functions, we could either use Mozilla JavaScript and XPCOM and/or Server-Side JavaScript (SSJS).

Perhaps an ideal future ambition for the project would be to see some high bandwidth site to host the library (e.g., as Yahoo has done with its AJAX library) so that it could be frequently used and cached by others without fear of the library modules (depending on which set(s) were chosen) taking up too much memory to be useful.

We might also work to add details about building migrating similar routines from one language to the other (e.g., that you can use "$" in JavaScript variable names), and, perhaps at a PHP wikia instead but referenced here, a PHP library to mimic the function/objects/methods/properties of JavaScript, prepending "js" and capitalizing the next word (in JavaScript style)--e.g., jsEval to avoid conflicts with the PHP function of the name, "eval".

Function librariesEdit

Array FunctionsEdit

Cross-reference between JavaScript functions and equivalent PHP/PHP-JavaScript functions (if any)Edit

Sorted by JavaScriptEdit

JavaScript PHP/PHP-JavaScript equivalent
Array.concat() array_merge()
Array.join() implode()
Array.pop() array_pop()
Array.push() array_push()
Array.reverse() array_reverse()
Array.shift() array_shift()
Array.slice() array_slice()
Array.sort() sort()
Array.unshift() array_unshift()

Sorted by PHP-JavaScriptEdit

PHP/PHP-JavaScript equivalent JavaScript
array_change_key_case() (none)
array_merge() Array.concat()
array_pop() Array.pop()
array_push() Array.push()
array_reverse() Array.reverse()
array_shift() Array.shift()
array_slice() Array.slice()
array_unshift() Array.unshift()
implode() Array.join()
sort() Array.sort()

Regular expressions Edit

PHP/PHP-JavaScript equivalent JavaScript
preg_split() String.split()

Around Wikia's network

Random Wiki