The Identification Number and Password fields need to be filled in. Moreover, you cannot send messages devoid of contents Adding further data is not allowed because this topic has been closed Print You provided no password: you have to write it in the textfield beside the command delete for the topic you want to delete Are you sure you want to delete this comment? You did not cast a vote. You need to cast a vote by selecting a radio button. Impossible to proceed Provide the project number Insufficient form parameters: you forgot to fill in some field/s
 
member picmember pic
 
Snippets of A
 
info Below you can find the text of the snippet you want to read, and the list of the other snippets by this author if available.
What are snippets?
Share on MySpace

Convert From Javascript Syntax To Php Syntax And From Php To Javascript

Snippet: Identification Number »   Snippet: Inclusion syntax »
Visitors: 50,554 Tagged by its author as: Programming Characters (in origin): 17,045 (pages: ~ 6)
Author: Em@il Permalink Cast your vote for this topic Remove color and border from headers Printable version
This file provides translation tables for Javascript and Php functions to swap one into the other.  
Of course, only translations for those instances where there are equivalent built in functions in both languages are provided.  
Related topic: Javascript From Php Unix Timestamp To Javascript Date.  
 
For instance Php deals also with databases, so all those Php functions that deal with databases will not have any Javascript translation tables because javascript has no functions that deal with databases.  
The same applies, for instance, to directory management too: Php has functions that can manage server directories and files; but Javascript, being exclusively client side, doesn't manipulate files.  
 
Conversely, there are many Javascript methods meant to deal with forms, windows, links etc, which do not have Php equivalents. As such, these methods won't be covered here because they have no Php homologic correspondence.  
 
All code elements that are meant as placeholders for whatever other variable names you may prefer start with the prefix: custom_  
 
Beware: Javascript syntax is always strictly case sensitive.  
 
Note: I use the Javascript operator typeof with round brackets - this does not mean I mistook it by a function.  
 
Note: if you have found this file useful and yet you deem you have found errors or typos or so you may send me an email at: Email  
Alternatively, join Full Poster (is free) and have fun cooperating.

STRING MANAGEMENT

Check whether it is a string  
JAVASCRIPT

typeof(custom_string1)=="string"
Remove colors  
PHP

is_string(custom_string1);
Remove colors  
Return length of string  
JAVASCRIPT

custom_string1.length 
Remove colors  
PHP

strlen(custom_string1); 
Remove colors  
From Ascii custom_number return its char and vice versa  
JAVASCRIPT

String.fromCharCode(custom_fromNum)
custom_fromChar.charCodeAt(0)
Remove colors  
fromCharCode is invoked using the String constructor as such, namely with a capital S.  
 
charCodeAt requires a string concatenated to it by a dot; pass its argument as zero to mean you want the code of the first char in the string, example:  
"y".charCodeAt(0)  
PHP

chr(custom_fromNum);
ord(custom_fromChar);
Remove colors  
Convert to upper or lower case a string  
JAVASCRIPT

custom_string1.toLowerCase()
custom_string1.toUpperCase()
Remove colors  
PHP

strtolower(custom_string1);
strtoupper(custom_string1); 
Remove colors  
Return numerical index of the first instance of a substring position within a wider string  
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: stripos 
Remove colors  
Find the char at a given numerical index  
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  
Return numerical index of the last instance of a substring position within a wider string  
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  
Return substring  
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  
Split a string  
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  
Replace instances in a string  
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  
Strip Tags from a String  
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  
Replace instances in a string  
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

ARRAY MANAGEMENT

Is that an array?  
JAVASCRIPT

typeof(custom_array1)=="object" 
Remove colors  
PHP

is_array(custom_array1) 
Remove colors  
Length of an array  
JAVASCRIPT

custom_array1.length 
Remove colors  
PHP

sizeof(custom_array1); 
Remove colors  
Join array entries into a string  
JAVASCRIPT

custom_array1.join(custom_stringJoiner) 
Remove colors  
PHP

implode(custom_stringJoiner, custom_string1); 
Remove colors  
Return length of string  
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  
Pop, push, shift, unshift on arrays  
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  
Reverse an array  
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  
Slice an array  
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  
Sort an array  
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_optionalFunction 

Remove colors

NUMBER MANAGEMENT

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  
Convert strings into numbers  
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  
Round a custom_number, get its absolute custom_value  
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  
Max and custom_min or random numbers  
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  
Pow and squares  
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  
Trigonometric functions  
JAVASCRIPT

Math.sin(); Math.cos(); Math.tan();

Math.asin(); Math.acos(); Math.atan(); 
Remove colors  
PHP

sin(); cos(); tan();

asin(); acos(); atan(); 
Remove colors  
Constants and logarhitms  
JAVASCRIPT

Math.PI; Math.log(custom_value) 
Remove colors  
PHP

pi();
log(custom_value); 
Remove colors

FUNCTION MANAGEMENT

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
Printable version To exclude hyperlinks from the print, check the checkbox »
Rss

Cast your vote for this topic

To perform this operation it is not necessary to be Full Poster members.
«Negative Positive»
Click here to save your vote (Current average: 6.38, Voters: 8)
Are you the author of this topic and do you want to append quickly more text? click here
Other topics
This subscriber has a blog too: Read the blog: 57 Shoutbox: 103 reviews: 153
Visitors: 50,554
Overall visits to all the topics: 4,958,337
Daily average (Calculated from the website subscription day): 2,059.97
Optional sorting commands:
Normal order: click here
Order by amount of visits: click here
Order by category: Programming
Current order: by category: Poetry
Other categories available for this author (Limited data report: 100):
Advice: Martial Arts and Self Defense(4), Books(236), Critical Reviews and Essays(4), Dictionaries(1), Emergency Care(4), Epistles Letters and Advice(5), Fantasy Epics and Fables(1), History and Documents(5), Humor and Jokes(2), Methematics(2), Music and Lyrics(6), News Digests and Press Reviews(1), Novels Poetry and Stories(3), Philosophy Reviews(7), Poetry(1), Programming(4), Programming Ajax(2), Programming Javascript(82), Programming Php(52), Psychology(1), Quotes(1), Religion Esoterica and Spirituality(12), Scientifical Reviews(4), Self Improvement(1), Sport Activities and Apparels(2), Tarots(1)
Showing topics: 1, 10
Available total: 448
View only a list of the snippets by this author: click here.
Other topics available for this author: click on any title below to view the complete item:
Poesie Del Disinganno Identification Number: 435 Visitors: 7,526
External services
This page of this subscriber uses external services: Hide