php-as-js v0.0.3
PHP-AS-JS
A JavaScript library that enables some PHP function for browsers.
addclass (_element, ...)
Type | Parameters | Description | Optional | |
---|---|---|---|---|
{element} | element | HTML element to add class on | ||
{array | string} | ... | Array or string of the class |
Returns {element}
The element with class added
date (format, timestamp)
Type | Parameters | Description | Optional |
---|---|---|---|
{string} | format | Support PHP date format | |
{number} | timestamp | Uses current time if not given | Yes |
Returns {string}
A formatted according to the given format
dayof_year (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{date} | var | A valid date object |
Returns {number}
The day of the year
empty (var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if empty, otherwise FALSE
getelement (_qs)
Type | Parameters | Description | Optional |
---|---|---|---|
{string} | qs | Query selector |
Returns {element|null}
The element if valid, otherwise NULL
getelements (_qs)
Type | Parameters | Description | Optional |
---|---|---|---|
{string} | qs | Query selector |
Returns {array|null}
An array of the elements if valid, otherwise NULL
gettype (var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {string}
The type of the given variable
md5 (var)
Type | Parameters | Description | Optional | Credit |
---|---|---|---|---|
{any} | var | The variable to hash | Paul Johnston |
Returns {string}
An MD5 hashed string
inarray (_needle, haystack, strict)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | needle | The value to search | |
{array} | haystack | The array to be searched | |
{boolean} | strict | Determine to check types |
Returns {boolean}
TRUE for found in the given array, otherwise FALSE
intval (var, base)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to convert | |
{number} | base | Default is 10 for decimal output and 16 for hex output | Yes |
Returns {number|string}
A converted decimal integer, or a hex string
isarray (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if an array, otherwise FALSE
isbool (_var)
| {any} | var | The variable to check | |
Returns {boolean}
TRUE if a boolean, otherwise FALSE
isfloat (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if a float, otherwise FALSE
isint (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if an integer, otherwise FALSE
isleap_year (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The year number to check |
Returns {boolean}
TRUE if a leap year, otherwise FALSE
isnull (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if NULL, otherwise FALSE
isobject (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if an object, otherwise FALSE
isstring (_var)
Type | Parameters | Description | Optional |
---|---|---|---|
{any} | var | The variable to check |
Returns {boolean}
TRUE if a string, otherwise FALSE
monthname (_n, short)
Type | Parameters | Description | Optional |
---|---|---|---|
{number} | n | The month number which is an integer between 0 and 11 | |
{boolean} | short | Determine if returns the first 3 letters or full names | Yes |
Returns {string}
The name of the month
sprintf (format, ...)
Type | Parameters | Description | Optional |
---|---|---|---|
{string} | format | Supports %s only at the moment | |
{string} | ... | variables to replace the format |
Returns {string}
The replaced string
ucfirst (str)
Type | Parameters | Description | Optional |
---|---|---|---|
{string} | str | Source string |
Returns {string}
The string with the first letter converted to uppercase
uniqid (len)
Type | Parameters | Description | Optional |
---|---|---|---|
{number} | len | The length of the generated hex string |
Returns {string}
The generated hex string
weekname (_n, short)
Type | Parameters | Description | Optional |
---|---|---|---|
{number} | n | Week number between 0 and 6 | |
{boolean} | short | Determine if return the first 3 letters or full names |
Returns {string}
The name of the week
weeknumber (_obj)
Type | Parameters | Description | Optional |
---|---|---|---|
{date} | obj | Date object |
Returns {number}
The week number in the year