PHPjed (PHP javascripted) brings PHP on your browser. It's a collection of about 275 PHP functions ported to Javascript and ready to be used on a website as a small client-side library (27kB minified and gzipped). A few examples of PHP functions ported are array_multisort
, date
, htmlentities
, isset
, preg_replace
, setcookie
, str_replace
, trim
, etc.
Include the minified file on your website. There are two PHPjed distributions:
-
The light distribution has 273 functions (92kB minified, 27kB gzipped*). The following HTML tag includes the latest version:
<script src="https://cdn.jsdelivr.net/gh/misaki-web/phpjed/dist/phpjed.min.js"></script>
It's possible to include a specific version, for example 1.0:
<script src="https://cdn.jsdelivr.net/gh/misaki-web/[email protected]/dist/phpjed.min.js"></script>
-
The complete distribution has 287 functions (142kB minified, 43kB gzipped*). The following HTML tag includes the latest version:
<script src="https://cdn.jsdelivr.net/gh/misaki-web/phpjed/dist/phpjed-all.min.js"></script>
It's possible to include a specific version, for example 1.0:
<script src="https://cdn.jsdelivr.net/gh/misaki-web/[email protected]/dist/phpjed-all.min.js"></script>
This distribution contains the functions from the light distribution and also includes the following functions:
addcslashes
crc32
date_parse
get_html_translation_table
metaphone
pack
sscanf
strptime
strtotime
unserialize
var_dump
var_export
xdiff_string_diff
xdiff_string_patch
All versions available are in the folder dist
. The latest version number can be retrieved programmatically from the URL https://raw.githubusercontent.com/misaki-web/phpjed/main/version.txt. Note that unminified and beautified versions of PHPjed are present in the folder dist/unminified
.
(*): When servers are configured to send data compressed with the deflate algorithm, this is the actual size of the file downloaded by users.
After including PHPjed on your website, functions are invoked using the namespace phpjed
. Examples:
var subject = "Hello world.";
var search = ["Hello", "world"];
var replace = ["Hi", "everybody"];
var hi_everybody = phpjed.str_replace(search, replace, subject);
Each function listed below is identified as follows:
- (LIGHT): included in the light (default) distribution of PHPjed
- (ALL): included in the complete distribution that contains all functions
A link to the corresponding function on the PHP manual is added.
- (LIGHT) abs
- (LIGHT) acos
- (LIGHT) acosh
- (ALL) addcslashes
- (LIGHT) addslashes
- (LIGHT) array_change_key_case
- (LIGHT) array_chunk
- (LIGHT) array_column
- (LIGHT) array_combine
- (LIGHT) array_count_values
- (LIGHT) array_diff
- (LIGHT) array_diff_assoc
- (LIGHT) array_diff_key
- (LIGHT) array_diff_uassoc
- (LIGHT) array_diff_ukey
- (LIGHT) array_fill
- (LIGHT) array_fill_keys
- (LIGHT) array_filter
- (LIGHT) array_flip
- (LIGHT) array_intersect
- (LIGHT) array_intersect_assoc
- (LIGHT) array_intersect_key
- (LIGHT) array_intersect_uassoc
- (LIGHT) array_intersect_ukey
- (LIGHT) array_keys
- (LIGHT) array_map
- (LIGHT) array_merge
- (LIGHT) array_merge_recursive
- (LIGHT) array_multisort
- (LIGHT) array_pad
- (LIGHT) array_pop
- (LIGHT) array_product
- (LIGHT) array_push
- (LIGHT) array_rand
- (LIGHT) array_reduce
- (LIGHT) array_replace
- (LIGHT) array_replace_recursive
- (LIGHT) array_reverse
- (LIGHT) array_search
- (LIGHT) array_shift
- (LIGHT) array_slice
- (LIGHT) array_splice
- (LIGHT) array_sum
- (LIGHT) array_udiff
- (LIGHT) array_udiff_assoc
- (LIGHT) array_udiff_uassoc
- (LIGHT) array_uintersect
- (LIGHT) array_uintersect_uassoc
- (LIGHT) array_unique
- (LIGHT) array_unshift
- (LIGHT) array_values
- (LIGHT) array_walk
- (LIGHT) array_walk_recursive
- (LIGHT) asin
- (LIGHT) asinh
- (LIGHT) assert_options
- (LIGHT) atan
- (LIGHT) atan2
- (LIGHT) atanh
- (LIGHT) base64_decode
- (LIGHT) base64_encode
- (LIGHT) basename
- (LIGHT) base_convert
- (LIGHT) bin2hex
- (LIGHT) bindec
- (LIGHT) boolval
- (LIGHT) ceil
- (LIGHT) checkdate
- (LIGHT) chop
- (LIGHT) chr
- (LIGHT) chunk_split
- (LIGHT) convert_uuencode
- (LIGHT) cos
- (LIGHT) cosh
- (LIGHT) count
- (LIGHT) count_chars
- (ALL) crc32
- (LIGHT) ctype_alnum
- (LIGHT) ctype_alpha
- (LIGHT) ctype_cntrl
- (LIGHT) ctype_digit
- (LIGHT) ctype_graph
- (LIGHT) ctype_lower
- (LIGHT) ctype_print
- (LIGHT) ctype_punct
- (LIGHT) ctype_space
- (LIGHT) ctype_upper
- (LIGHT) ctype_xdigit
- (LIGHT) current
- (LIGHT) date
- (ALL) date_parse
- (LIGHT) decbin
- (LIGHT) dechex
- (LIGHT) decoct
- (LIGHT) deg2rad
- (LIGHT) dirname
- (LIGHT) doubleval
- (LIGHT) echo
- (LIGHT) empty
- (LIGHT) end
- (LIGHT) escapeshellarg
- (LIGHT) exp
- (LIGHT) explode
- (LIGHT) expm1
- (LIGHT) floatval
- (LIGHT) floor
- (LIGHT) fmod
- (LIGHT) function_exists
- (LIGHT) getdate
- (LIGHT) getenv
- (LIGHT) getrandmax
- (LIGHT) gettimeofday
- (LIGHT) gettype
- (LIGHT) get_defined_functions
- (ALL) get_html_translation_table
- (LIGHT) gmdate
- (LIGHT) gmmktime
- (LIGHT) gmstrftime
- (LIGHT) hex2bin
- (LIGHT) hexdec
- (LIGHT) htmlentities
- (LIGHT) htmlspecialchars
- (LIGHT) htmlspecialchars_decode
- (LIGHT) html_entity_decode
- (LIGHT) http_build_query
- (LIGHT) hypot
- (LIGHT) idate
- (LIGHT) implode
- (LIGHT) inet_ntop
- (LIGHT) inet_pton
- (LIGHT) ini_get
- (LIGHT) ini_set
- (LIGHT) intval
- (LIGHT) in_array
- (LIGHT) ip2long
- (LIGHT) isset
- (LIGHT) is_array
- (LIGHT) is_bool
- (LIGHT) is_double
- (LIGHT) is_finite
- (LIGHT) is_float
- (LIGHT) is_infinite
- (LIGHT) is_int
- (LIGHT) is_integer
- (LIGHT) is_long
- (LIGHT) is_nan
- (LIGHT) is_null
- (LIGHT) is_numeric
- (LIGHT) is_object
- (LIGHT) is_scalar
- (LIGHT) is_string
- (LIGHT) join
- (LIGHT) json_encode
- (LIGHT) json_last_error
- (LIGHT) lcfirst
- (LIGHT) lcg_value
- (LIGHT) levenshtein
- (LIGHT) localeconv
- (LIGHT) log
- (LIGHT) log1p
- (LIGHT) log10
- (LIGHT) long2ip
- (LIGHT) ltrim
- (LIGHT) max
- (ALL) metaphone
- (LIGHT) microtime
- (LIGHT) min
- (LIGHT) mktime
- (LIGHT) mt_getrandmax
- (LIGHT) mt_rand
- (LIGHT) natcasesort
- (LIGHT) natsort
- (LIGHT) next
- (LIGHT) nl2br
- (LIGHT) nl_langinfo
- (LIGHT) number_format
- (ALL) pack
- (LIGHT) parse_str
- (LIGHT) parse_url
- (LIGHT) pathinfo
- (LIGHT) pi
- (LIGHT) pos
- (LIGHT) pow
- (LIGHT) preg_match
- (LIGHT) preg_quote
- (LIGHT) preg_replace
- (LIGHT) prev
- (LIGHT) printf
- (LIGHT) print_r
- (LIGHT) quoted_printable_decode
- (LIGHT) quoted_printable_encode
- (LIGHT) quotemeta
- (LIGHT) rad2deg
- (LIGHT) rand
- (LIGHT) range
- (LIGHT) rawurldecode
- (LIGHT) rawurlencode
- (LIGHT) reset
- (LIGHT) round
- (LIGHT) rtrim
- (LIGHT) serialize
- (LIGHT) setcookie
- (LIGHT) setlocale
- (LIGHT) setrawcookie
- (LIGHT) set_time_limit
- (LIGHT) shuffle
- (LIGHT) similar_text
- (LIGHT) sin
- (LIGHT) sinh
- (LIGHT) sizeof
- (LIGHT) soundex
- (LIGHT) sprintf
- (LIGHT) sqrt
- (ALL) sscanf
- (LIGHT) strcasecmp
- (LIGHT) strchr
- (LIGHT) strcmp
- (LIGHT) strcoll
- (LIGHT) strcspn
- (LIGHT) strftime
- (LIGHT) stripos
- (LIGHT) stripslashes
- (LIGHT) strip_tags
- (LIGHT) stristr
- (LIGHT) strlen
- (LIGHT) strnatcasecmp
- (LIGHT) strnatcmp
- (LIGHT) strncasecmp
- (LIGHT) strncmp
- (LIGHT) strpbrk
- (LIGHT) strpos
- (ALL) strptime
- (LIGHT) strrchr
- (LIGHT) strrev
- (LIGHT) strripos
- (LIGHT) strrpos
- (LIGHT) strspn
- (LIGHT) strstr
- (LIGHT) strtok
- (LIGHT) strtolower
- (ALL) strtotime
- (LIGHT) strtoupper
- (LIGHT) strtr
- (LIGHT) strval
- (LIGHT) str_getcsv
- (LIGHT) str_ireplace
- (LIGHT) str_pad
- (LIGHT) str_repeat
- (LIGHT) str_replace
- (LIGHT) str_rot13
- (LIGHT) str_shuffle
- (LIGHT) str_split
- (LIGHT) str_word_count
- (LIGHT) substr
- (LIGHT) substr_compare
- (LIGHT) substr_count
- (LIGHT) substr_replace
- (LIGHT) uasort
- (LIGHT) ucfirst
- (LIGHT) ucwords
- (LIGHT) uksort
- (LIGHT) uniqid
- (ALL) unserialize
- (LIGHT) urldecode
- (LIGHT) urlencode
- (LIGHT) usort
- (LIGHT) utf8_decode
- (LIGHT) utf8_encode
- (ALL) var_dump
- (ALL) var_export
- (LIGHT) version_compare
- (LIGHT) vprintf
- (LIGHT) vsprintf
- (LIGHT) wordwrap
- (ALL) xdiff_string_diff
- (ALL) xdiff_string_patch
- (LIGHT)
_php_cast_float
: helper function - (LIGHT)
_php_cast_int
: helper function - (LIGHT)
_php_cast_string
: helper function
PHPjed is based on Locutus (formerly php.js). Locutus is packaged for Node.js and distributed through npm. It requires a few Node.js modules and is not suitable to use as a client-side library.
PHPjed has a custom builder (phpjed-builder.sh
, developed and tested on GNU/Linux and Bash 5) to achieve the following points:
- merge all required files from the Locutus npm package and get all code in a single file
- convert the "module exports" and "require" instructions to have a file usable in browsers
- remove functions dependant on Node.js modules (these functions are server-side only)
- remove deprecated and undocumented PHP functions as of PHP 8
- for improved security, remove functions that make use of
eval()
- rename camel case functions
- put larger functions in a separate distribution
- add a namespace (
phpjed
by default) to prevent naming collisions - minify the generated Javascript files
Help about the PHPjed builder can be invoked with ./phpjed-builder.sh -h
. PHPjed is distributed with prebuilt Javascript files in the folder dist
, but one can build PHPjed themselves, for example to have a custom namespace.
After running the builder, generated files are saved in a newly created subfolder in data/custom-builds
. Here's an example for the light (default) distribution:
- Folder:
/tmp/phpjed/data/custom-builds/20210901-143916-53
- Namespace:
phpjed
; example:phpjed.is_int(5)
- Distribution: light (default)
FILE NAME | SIZE (in KiB) | SIZE REDUCTION |
---|---|---|
phpjed.js | 361.31 | - |
phpjed.min.js | 92.35 | 74.44% |
phpjed.min.js.gz | 26.90 | 92.56% |
Here's an example for the complete distribution including all functions:
- Folder:
/tmp/phpjed/data/custom-builds/20210901-144109-39
- Namespace:
phpjed
; example:phpjed.is_int(5)
- Distribution: all
FILE NAME | SIZE (in KiB) | SIZE REDUCTION |
---|---|---|
phpjed-all.js | 487.94 | - |
phpjed-all.min.js | 142.27 | 70.84% |
phpjed-all.min.js.gz | 43.26 | 91.14% |
PHPjed (the builder and Javascript files generated) is released under the MIT License. See the file LICENSE.md
.