Use PHP functions in JavaScript

Functions overview

Here is a list of functions currently implemented by php.js. Missing functions can be found here.

Arrays

  • array
  • array_change_key_case
  • array_chunk
  • array_combine
  • array_count_values
  • array_diff
  • array_diff_assoc
  • array_diff_key
  • array_diff_uassoc
  • array_diff_ukey
  • array_fill
  • array_fill_keys
  • array_filter
  • array_flip
  • array_intersect
  • array_intersect_assoc
  • array_intersect_key
  • array_intersect_uassoc
  • array_intersect_ukey
  • array_key_exists
  • array_keys
  • array_map
  • array_merge
  • array_merge_recursive
  • array_multisort
  • array_pad
  • array_pop
  • array_product
  • array_push
  • array_rand
  • array_reduce
  • array_replace
  • array_replace_recursive
  • array_reverse
  • array_search
  • array_shift
  • array_slice
  • array_splice
  • array_sum
  • array_udiff
  • array_udiff_assoc
  • array_udiff_uassoc
  • array_uintersect
  • array_uintersect_assoc
  • array_uintersect_uassoc
  • array_unique
  • array_unshift
  • array_values
  • array_walk
  • array_walk_recursive
  • arsort
  • asort
  • compact
  • count
  • current
  • each
  • end
  • extract
  • in_array
  • key
  • krsort
  • ksort
  • natcasesort
  • natsort
  • next
  • pos
  • prev
  • range
  • reset
  • rsort
  • shuffle
  • sizeof
  • sort
  • uasort
  • uksort
  • usort

BCMath Arbitrary Precision Mathematics

  • bcadd
  • bccomp
  • bcdiv
  • bcmul
  • bcround
  • bcscale
  • bcsub

Character type checking

  • ctype_alnum
  • ctype_alpha
  • ctype_cntrl
  • ctype_digit
  • ctype_graph
  • ctype_lower
  • ctype_print
  • ctype_punct
  • ctype_space
  • ctype_upper
  • ctype_xdigit

Class/Object Information

  • class_alias
  • class_exists
  • get_class
  • get_class_methods
  • get_class_vars
  • get_declared_classes
  • get_object_vars
  • method_exists
  • property_exists

Classkit

  • classkit_import
  • classkit_method_add
  • classkit_method_copy
  • classkit_method_redefine
  • classkit_method_remove
  • classkit_method_rename

Date and Time

  • checkdate
  • date
  • date_default_timezone_get
  • date_default_timezone_set
  • date_parse
  • getdate
  • gettimeofday
  • gmdate
  • gmmktime
  • gmstrftime
  • idate
  • localtime
  • microtime
  • mktime
  • strftime
  • strptime
  • strtotime
  • time
  • timezone_abbreviations_list
  • timezone_identifiers_list

Error Handling and Logging

  • error_get_last
  • error_reporting
  • trigger_error
  • user_error

Filesystem

  • basename
  • dirname
  • fclose
  • feof
  • fgetc
  • fgetcsv
  • fgets
  • fgetss
  • file
  • file_exists
  • file_get_contents
  • filemtime
  • filesize
  • fopen
  • fpassthru
  • fread
  • fscanf
  • fseek
  • ftell
  • pathinfo
  • pclose
  • popen
  • readfile
  • realpath
  • rewind

Function Handling

  • call_user_func
  • call_user_func_array
  • create_function
  • forward_static_call
  • forward_static_call_array
  • func_get_arg
  • func_get_args
  • func_num_args
  • function_exists
  • get_defined_functions
  • register_shutdown_function

JavaScript Object Notation

  • json_decode
  • json_encode
  • json_last_error

Language & Control Structures

  • include
  • include_once
  • require
  • require_once

Mail

  • mail

Mathematical Functions

  • abs
  • acos
  • acosh
  • asin
  • asinh
  • atan
  • atan2
  • atanh
  • base_convert
  • bindec
  • ceil
  • cos
  • cosh
  • decbin
  • dechex
  • decoct
  • deg2rad
  • exp
  • expm1
  • floor
  • fmod
  • getrandmax
  • hexdec
  • hypot
  • is_finite
  • is_infinite
  • is_nan
  • lcg_value
  • log
  • log10
  • log1p
  • max
  • min
  • mt_getrandmax
  • mt_rand
  • octdec
  • pi
  • pow
  • rad2deg
  • rand
  • round
  • sin
  • sinh
  • sqrt
  • tan
  • tanh

Miscellaneous Functions

  • constant
  • define
  • defined
  • pack
  • php_strip_whitespace
  • time_sleep_until
  • uniqid

Net Gopher

  • gopher_parsedir

Network

  • inet_ntop
  • inet_pton
  • ip2long
  • long2ip
  • setcookie
  • setrawcookie

Object Aggregation/Composition

  • aggregate
  • aggregate_info
  • aggregate_methods
  • aggregate_methods_by_list
  • aggregate_methods_by_regexp
  • aggregate_properties
  • aggregate_properties_by_list
  • aggregate_properties_by_regexp
  • aggregation_info
  • deaggregate

Output Buffering Control

  • ob_clean
  • ob_end_clean
  • ob_end_flush
  • ob_flush
  • ob_get_clean
  • ob_get_contents
  • ob_get_flush
  • ob_get_length
  • ob_get_level
  • ob_get_status
  • ob_list_handlers
  • ob_start

PHP Options and Information

  • assert
  • assert_options
  • get_cfg_var
  • get_defined_constants
  • get_extension_funcs
  • get_include_path
  • get_included_files
  • get_required_files
  • getenv
  • getlastmod
  • ini_alter
  • ini_get
  • ini_get_all
  • ini_restore
  • ini_set
  • php_ini_loaded_file
  • php_ini_scanned_files
  • phpversion
  • putenv
  • restore_include_path
  • set_include_path
  • set_time_limit
  • version_compare

Program execution Functions

  • escapeshellarg

Regular Expressions (Perl-Compatible)

  • preg_grep
  • preg_quote
  • sql_regcase

Streams

  • stream_context_create
  • stream_context_get_default
  • stream_context_get_options
  • stream_context_get_params
  • stream_context_set_default
  • stream_context_set_option
  • stream_context_set_params
  • stream_get_contents
  • stream_get_line
  • stream_is_local

Strings

  • addcslashes
  • addslashes
  • bin2hex
  • chop
  • chr
  • chunk_split
  • convert_cyr_string
  • convert_uuencode
  • count_chars
  • crc32
  • echo
  • explode
  • get_html_translation_table
  • html_entity_decode
  • htmlentities
  • htmlspecialchars
  • htmlspecialchars_decode
  • implode
  • join
  • lcfirst
  • levenshtein
  • localeconv
  • ltrim
  • md5
  • md5_file
  • metaphone
  • money_format
  • nl2br
  • nl_langinfo
  • number_format
  • ord
  • parse_str
  • printf
  • quoted_printable_decode
  • quoted_printable_encode
  • quotemeta
  • rtrim
  • setlocale
  • sha1
  • sha1_file
  • similar_text
  • soundex
  • split
  • sprintf
  • sscanf
  • str_getcsv
  • str_ireplace
  • str_pad
  • str_repeat
  • str_replace
  • str_rot13
  • str_shuffle
  • str_split
  • str_word_count
  • strcasecmp
  • strchr
  • strcmp
  • strcoll
  • strcspn
  • strip_tags
  • stripos
  • stripslashes
  • stristr
  • strlen
  • strnatcasecmp
  • strnatcmp
  • strncasecmp
  • strncmp
  • strpbrk
  • strpos
  • strrchr
  • strrev
  • strripos
  • strrpos
  • strspn
  • strstr
  • strtok
  • strtolower
  • strtoupper
  • strtr
  • substr
  • substr_compare
  • substr_count
  • substr_replace
  • trim
  • ucfirst
  • ucwords
  • vprintf
  • vsprintf
  • wordwrap

URLs

  • base64_decode
  • base64_encode
  • get_headers
  • get_meta_tags
  • http_build_query
  • parse_url
  • rawurldecode
  • rawurlencode
  • urldecode
  • urlencode

Variable handling

  • doubleval
  • empty
  • floatval
  • get_defined_vars
  • get_resource_type
  • gettype
  • import_request_variables
  • intval
  • is_array
  • is_binary
  • is_bool
  • is_buffer
  • is_callable
  • is_double
  • is_float
  • is_int
  • is_integer
  • is_long
  • is_null
  • is_numeric
  • is_object
  • is_real
  • is_resource
  • is_scalar
  • is_string
  • is_unicode
  • isset
  • print_r
  • serialize
  • settype
  • strval
  • unserialize
  • var_dump
  • var_export

XML Parser

  • utf8_decode
  • utf8_encode

[internal] php.js shared libs

    i18n

    • i18n_loc_get_default
    • i18n_loc_set_default

    runkit

    • runkit_class_adopt
    • runkit_class_emancipate
    • runkit_function_add
    • runkit_function_copy
    • runkit_function_redefine
    • runkit_function_remove
    • runkit_function_rename
    • runkit_import
    • runkit_method_add
    • runkit_method_copy
    • runkit_method_redefine
    • runkit_method_remove
    • runkit_method_rename
    • runkit_superglobals

    xdiff

    • xdiff_string_diff
    • xdiff_string_patch

    Download

    There is a wide variety of packages if the default doesn't suit you.
    You can also compile your own package to avoid any overhead.

    Support us

    spread the word:


    Use any PHP function in JavaScript


    These kind folks have already donated: AYHAN BARI*, Nikita Ekshiyan, Nikita Ekshiyan, Petr Pavel, @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
    <your name here>

    spacer

    RSS

    • Comments
    • Functions

    Tweets

    • Brett
    • Kevin
    • php.js

    Comments

    • 432
    • Math.fmod = function(x, y) { // Returns th...
    • Math.fmod = function(x, y) { // Returns th...
    • It doesn't work!
    • String.fromCharCode accepts several arguments. ...
    • test
    • @danny morabito: This is not just checking whet...
    • sorry, but isn't simplier: return this.window[...
    • This should be marked as having a dependency on...
    • Here is another implementation of the array_dif...
    • Yesterday I got same problem : malformed URI se...
    • Thanks , grate job ;)
    • To add clarification to my last post regarding ...
    • Hello Ali.MD, There are indeed client-side use...
    • its wrong . you load content of file to check i...
    • The breakTag variable doesn't display correctly.
    • eho dali shte e OK
    • Is this function only checking if a variable ha...
    • tl;dr - On line 89, change [] to {} so that it ...
    • The o for ISO-8601 year is wrong! date, ...
    • echo(date("Y-m-d H:i:s", strtotime("last monday...
    • I fixed this function over at jsphp.co: http:/...
    • I suggest you my version which has two main fea...
    • Funny
    • I installed this module v1.3_0208 I received it...
    • <script>alert('hi')</script>
    • dfgr dhfgdh
    • thank you so much, you saved my life :D :D
    • I agree with other posters that the utf8_decode...
    • The function date_default_timezone_set(), but I...

    Who uses php.js

    • Ext for Yii
    • node.js
    • ShaniaTwain.com
    • KillBugs
    • XSoftware Corporation
    • TwiPho
    • mediacode
    • Sprink
    • Harmony Framework

    If you use php.js, let us know and get linked.

    gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.