![]()
Snippets of A |
|
|
What are snippets? |
|
custom_
typeof with round brackets - this does not mean I mistook it by a function.
JAVASCRIPT typeof(custom_string1)=="string"Remove colors
PHP is_string(custom_string1);Remove colors
JAVASCRIPT
custom_string1.length
Remove colors
PHP strlen(custom_string1);Remove colors
JAVASCRIPT String.fromCharCode(custom_fromNum) custom_fromChar.charCodeAt(0)Remove colors
PHP chr(custom_fromNum); ord(custom_fromChar);Remove colors
JAVASCRIPT custom_string1.toLowerCase() custom_string1.toUpperCase()Remove colors
PHP strtolower(custom_string1); strtoupper(custom_string1);Remove colors
JAVASCRIPT custom_string1.indexOf( custom_string2, custom_fromNum ) Upon failure (string 2 not present within custom_string1, returns -1) To make is case insensitive: custom_string1.toLowerCase().indexOf( custom_string2.toLowerCase(), custom_fromNum )Remove colors
PHP strpos( custom_string1, custom_string2, custom_fromNum ); Upon failure (string 2 not present within custom_string1, returns false; since false is the same as zero -fisrt position in the string- to check whether strpos has returned false, do not use comparison check == but the identity check: === namely if strpos(blabla)===false ) To make it case insensitive use: stripos( custom_string1, custom_string2, custom_fromNum ); note the i: striposRemove colors
JAVASCRIPT custom_string1.charAt(custom_number)Remove colors
PHP substr(custom_string1, custom_number, 1); $custom_string1[custom_number]; php, unlike javascript, allows for addressing a string like an array of chars too, that is through square brackets indexing of the string itself.Remove colors
JAVASCRIPT custom_string1.lastIndexOf( custom_string2, custom_fromNum ) Upon failure (string 2 not present within custom_string1, returns -1) To make is case insensitive: custom_string1.toLowerCase().lastIndexOf( custom_string2.toLowerCase(), custom_fromNum )Remove colors
PHP For Php 5 onward you can use: strrpos(custom_string1, custom_string2, custom_fromNum); Upon failure returns boolean false, to discriminate it from zero use for comparisons the === operator. The case insensitive version is: strripos(custom_string1, custom_string2, custom_fromNum); note the i in the function name.Remove colors
JAVASCRIPT custom_string1.substring( custom_fromNum, toNum ) custom_string1.substr( custom_fromNum, length )Remove colors
PHP substr( custom_string1, custom_fromNum, (toNum-custom_fromNum) ); substr( custom_string1, custom_fromNum, custom_lengthOfItem);Remove colors
PHP substr( custom_string1, custom_fromNum, custom_lengthOfItem );Remove colors
JAVASCRIPT custom_string1.substr(custom_fromNum, length) custom_string1.substring( custom_fromNum, (custom_fromNum+length) )Remove colors
PHP strstr( custom_string1, custom_string2 );Remove colors
JAVASCRIPT custom_string1.substring( custom_string1.indexOf(custom_string2) )Remove colors
JAVASCRIPT custom_string1.split(stringSplitter)Remove colors
PHP explode(stringSplitter, custom_string1); explode does not accept an empty splitter such as "" in php, though javascript would accept it. To split by an empty splitter, use in PHP preg_split( "//", custom_string1); the two forward slashes are the delimiters of a regular expression, and encapsulating in this case nothing they amount to an empty splitter. Note that with preg_split the hidden chars such as those of starting line or new line are included, therefore the first entry [0] of the returned splitted array would be an empty slot. Any break of line would then be reflected as two apparently "empty" returned array slots, one for the carriage return hidden char, the other for the new line hidden char.Remove colors
JAVASCRIPT custom_string1.replace( custom_findThis, custom_replaceWithThis ) custom_string1.replace( custom_regularExpression, custom_replaceWithThis )Remove colors
PHP str_replace( custom_findThis, custom_replaceWithThis, custom_string1 ); this function replaces all instances. preg_replace( custom_regularExpression, custom_replaceWithThis, custom_string1 ); custom_regularExpression must be in between quotes, unlike JAVASCRIPT "/regexp here/"Remove colors
PHP substr_replace( custom_string1, custom_replaceWithThis, custom_fromNumIndex, custom_lengthOfItem );Remove colors
JAVASCRIPT custom_string1.replace( custom_string1.substring( custom_fromNumIndex, (custom_fromNumIndex+length) ), custom_replaceWithThis )Remove colors
JAVASCRIPT In Javascript we use a replacement, for no specific method is available for this task as in PHP custom_string1=custom_string1.replace(/<[^>]+>/g, '');Remove colors
PHP custom_string1=striptags(custom_string1);Remove colors
JAVASCRIPT custom_string1.replace( custom_findThis, custom_replaceWithThis ) custom_string1.replace( custom_regularExpression, custom_replaceWithThis )Remove colors
PHP str_replace( custom_findThis, custom_replaceWithThis, custom_string1 ); this function replaces all instances. preg_replace( custom_regularExpression, custom_replaceWithThis, custom_string1 ); custom_regularExpression must be in between quotes, unlike JAVASCRIPT "/regexp here/"Remove colors
PHP substr_replace( custom_string1, custom_replaceWithThis, custom_fromNumIndex, custom_lengthOfItem );Remove colors
JAVASCRIPT custom_string1.replace( custom_string1.substring( custom_fromNumIndex, (custom_fromNumIndex+length) ), custom_replaceWithThis )Remove colors Is that an array?
JAVASCRIPT typeof(custom_array1)=="object"Remove colors
PHP is_array(custom_array1)Remove colors
JAVASCRIPT
custom_array1.length
Remove colors
PHP sizeof(custom_array1);Remove colors
JAVASCRIPT custom_array1.join(custom_stringJoiner)Remove colors
PHP implode(custom_stringJoiner, custom_string1);Remove colors
JAVASCRIPT custom_array1.concat(custom_array2, custom_array3...) This javascript method will not concatenate associative arrays namely arrays whose indexes are not uniquely numerical.Remove colors
PHP array_merge(custom_array1, custom_array2, custom_array3...); array_merge_recursive(custom_array1, custom_array2, custom_array3...); This latter php method will concatenate associative arrays too namely arrays whose indexes are not uniquely numerical. From php.net: If the input arrays have the same string keys, then the values for these keys are merged together into an array, and this is done recursively, so that if one of the values is an array itself, the function will merge it with a corresponding entry in another array too. If, however, the arrays have the same numeric key, the later custom_value will not overwrite the original custom_value, but will be appended.Remove colors
JAVASCRIPT custom_array1.shift() custom_array1.unshift(custom_value) custom_array1.pop() custom_array1.push(custom_value)Remove colors
PHP array_shift(custom_array1); array_unshift(custom_array1, custom_value); array_pop(custom_array1); array_push(custom_array1, custom_value);Remove colors
JAVASCRIPT custom_array1.reverse()Remove colors
PHP array_reverse(custom_array1); This function accepts a second parameter, if passed as keyword true the arry is reversed but the indexes still the same. To reset the indexes of an array in PHP custom_array1=array_values(custom_array1);Remove colors
JAVASCRIPT custom_array1.slice(custom_startIndex, custom_endIndex) Original custom_array1 not affected, the sliced subsegment is released as an array of its own. custom_array1.splice(custom_startIndex, custom_lengthOfItem) Original custom_array1 is affected. This latter function allows for a third argument, which must be an array: if provided, in the original array the spliced (removed, for original is affected) subsection is just replaced with it. Note that in javascript the third argument is an index with slice and a length with splice.Remove colors
PHP array_slice( custom_array1, custom_startIndex, (custom_endIndex-custom_startIndex) ); Original not affected. array_splice( custom_array1, custom_startIndex, custom_lengthOfItem ); Original custom_array1 is affected. This latter function allows for a fourth argument, which must be an array: if provided, in the original array the spliced (removed, for original is affected) subsection is just replaced with it.Remove colors
PHP array_slice( custom_array1, custom_startIndex, custom_lengthOfItem ); array_splice( custom_array1, custom_startIndex, custom_lengthOfItem );Remove colors
JAVASCRIPT custom_array1.slice(custom_startIndex, (custom_startIndex+custom_lengthOfItem)) custom_array1.splice(custom_startIndex, custom_lengthOfItem)Remove colors
JAVASCRIPT custom_array1.sort(custom_optionalFunction)Remove colors
PHP sort(custom_array1); You have a wide family of sorters in php as such: rsort ; Sort an array in reverse order ksort ; Sort an array by key krsort ; Sort an array by key in reverse order natsort ; Sort an array using a natural order algorithm (what in javascript we called custom_optionalFunction) natcasesort ; Sort an array using a case insensitive natural order algorithm (what in javascript we called custom_optionalFunction) usort(custom_array1, custom_optionalFunction) ; Sort an array with a user-defined custom_optionalFunction uksort(custom_array1, custom_optionalFunction) ; Sort an array by keys with a user-defined custom_optionalFunction uasort(custom_array1, custom_optionalFunction) ; Sort an array with a user-defined custom_optionalFunctionRemove colors Is it a custom_number?
JAVASCRIPT isNaN(custom_number) returns true if it is not a custom_number. Yet also numerical strings (so called literal numbers, say: "12") are reported as numbers. Note that the typeof of a non custom_number returned by isNan is, confusing enough: "custom_number"Remove colors
PHP is_nan(custom_number); is_numeric(custom_number); returns true if it is not a custom_number. Yet also numerical strings (so called literal numbers, say: "12") are reported as numbers. is_integer(custom_number); returns false if custom_number has floating digits. Literal numbers (in between quotes) return false. is_double(custom_number); returns false if custom_number has no floating digits. Literal numbers (in between quotes) return false.Remove colors
JAVASCRIPT parseInt(custom_string1) parseFloat(custom_string1)Remove colors
PHP (integer)custom_string1; (double)custom_string1; The procedure above is called data type casting.Remove colors
JAVASCRIPT Math.floor(custom_number); Math.ceil(custom_number); Math.round(custom_number); Mat.abs(custom_number);Remove colors
PHP ceil( custom_number ); floor( custom_number ); round( custom_number ); abs( custom_number );Remove colors
JAVASCRIPT Math.max(custom_number1, custom_number2) Math.min(custom_number1, custom_number2) (Math.random()*(custom_max-custom_min))+custom_min custom_min and custom_max are optional. If omitted, this function just generates a fractional custom_number included between 0 and 1. To produce only non fractional numbers you may use: Math.round( (Math.random()*(custom_max-custom_min))+custom_min )Remove colors
PHP max(custom_number1, custom_number2); min(custom_number1, custom_number2); mt_rand(custom_min, custom_max); custom_min and custom_max are optional. If omitted, this function just generates a custom_number up to ten digits long. Prior to Php 4.2.0 you have also to feed the seed by calling first: mt_srand((double)microtime()*1000000) just like that!Remove colors
JAVASCRIPT Math.pow(custom_number, custom_power) Math.sqrt(custom_number) Math.pow(custom_number, 1/custom_root) Above is the x custom_root of a custom_number, for Math.sqrt provides only square roots.Remove colors
PHP pow(custom_number, custom_power); sqrt(custom_number); pow(custom_number, 1/custom_root); Above is the x custom_root of a custom_number, for sqrt provides only square roots.Remove colors
JAVASCRIPT Math.sin(); Math.cos(); Math.tan(); Math.asin(); Math.acos(); Math.atan();Remove colors
PHP sin(); cos(); tan(); asin(); acos(); atan();Remove colors
JAVASCRIPT Math.PI; Math.log(custom_value)Remove colors
PHP pi(); log(custom_value);Remove colors Return length of string
JAVASCRIPT typeof(custom_functionName)=="function"; //is it a function? This must be called inside the function custom_functionName: custom_functionName.arguments.length; custom_functionName.arguments; //array of args custom_functionName.arguments[custom_number];Remove colors
PHP function_exists("custom_functionName"); //is it a function? This must be called inside the function custom_functionName: func_num_args(); func_get_args(); //array of args func_get_arg(Number)Remove colors