ASP/PHP/Javascript/SQL Cross Reference

ASP/PHP/Javascript/SQL Cross Reference

Python/Applescript cross reference.

Command ASP3 (VBScript 5.6) PHP Javascript (ECMAscript) MS SQL (2000+)
General syntax
Comments, inline 'my dog has fleas //my dog has fleas // comment -- comment
Comments, block Not available
Small workaround:

If 2 == 1 Then
.. do stuff
End If

("do stuff" must contain valid code.)
  The quick brown fox
  jumped over the lazy dogs.
/* lines of code */ /* lines of code */
Command termination None ; ; None
Quotes " " or ' ' '
Escaping quotes ""
"var text1=""<img src=\""blank.gif\"">"";"
\" or use ' to quote and just " to write \' ''
Multiple commands per line Separate with : Allowed Allowed ?
Screen output Response.Write("hello") echo "hello"; document.write('hello'); PRINT 'hello'
Newline characters vbCrLf, outside quotes Response.Write("hello" & vbCrLf) "\n", inside quotes (must be inside "", not '') echo "hello \n"; ? ?
Equality test 2 = 3 2 = 2, 2 <> 3 2 == 32 = 2, 2 != 3 2 == 3 2 = 3
Case sensitivity Everything is case insensitive Variables case sensitive, functions and commands insensitive Everything is case sensitive Everything is case insensitive
Variable names Case insensitive,
so strName is the same as STRNAME
Case sensitive AND must begin with $
so $fName is NOT the same as $FNAME
Case sensitive Case insensitive AND must begin with @
Usual naming convention variables Hungarian notation strName, intZipCode ? Camel case thisIsVariable Pascal Casing @Name
Usual naming convention functions Pascal Casing MyFunction ? Camel case myFunction Pascal Casing MyFunction
Unsorted (Class, session)
Class delimiter . -> ? ?
Function kald Call Test(var1, var2)
Function(var1, var2)
'Alle funktionens parametre skal stå i kaldet
? ? ?
Function kald fra samme class Call Test() $this->test ? ?
Function kald fra anden class Call Regular.Test() $regular->test ? ?
Session Session("name") $_SESSION["name"] ?
Include outside code <!--#include virtual="/"-->
<!--#include file="/"-->
<script language="vbscript" runat="server" src="/"<>/script>
? document.write("<SCR" + "IPT language=\"Javascript\" src=\"filename.js\"><SCRIPT>"); ?
Execute inside code Server.Execute("")
require, require_once, include, include_once (include will only include the file if the line it's in actually executes, and will continue on errors) ? ?
Control Structures
If statements
if x=100 then
elseif x<200 then 
end if
If (1 = 1) Or (2 = 2) Then
If (1 = 1) And (2 = 2) Then
If (1 = 2) And (function()) Then (function bliver eksekveret, selvom det er overflødigt, da sætningen aldrig bliver sand)
if ($x==100) { 
else if ($x<200) { 
else { 
if (1 == 1 || 2 == 2)
if (1 == 1 && 2 == 2)
if (1 == 2 && function()) (function bliver ikke eksekveret, da det er overflødigt, da sætningen aldrig bliver sand)
For loops
for x=0 to 100 step 2 
if x>p then exit for
for ($x=0; $x<=100; $x+=2) { 
if ($x>$p) {break;}
While loops
do while x<100 
if x>p then exit do
while ($x<100) { 
if ($x>$p) {break;}
select case chartName
case "TopSales"
theTitle="Best Sellers"
case "TopSingles"
theTitle="Singles Chart"
case "TopAlbums"
theTitle="Album Chart"
case else
theTitle="Not Found"
end select
switch ($chartName) {
case "TopSales":
$theTitle="Best Sellers"; $theClass="S";
case "TopSingles":
$theTitle="Singles Chart"; $theClass="S";
case "TopAlbums":
$theTitle="Album Chart"; $theClass="A";
$theTitle="Not Found";
Functions and procedures
Function myFunction(x)
myFunction = x*16  'Return value
End Function
function myFunction($x) {
return $x*16;  //Return value
String Functions
ASP String concatenation

fname=name1 & " " & name2
emsg=emsg & "error!"
PHP String concatenation
. and .=

$fname=$name1." ".$name2;
ASP, Change case
LCase(), UCase()

PHP, Change case
strtolower(), strtoupper()

ASP String length

PHP String length

ASP, Trim whitespace

PHP, Trim whitespace
trim() and also ltrim(), rtrim()

ASP String sections
Left(), Right(), Mid()
	Left("abcdef",3)      result = "abc"
	Right("abcdef",2)     result = "ef"
	Mid("abcdef",3)       result = "cdef"
	Mid("abcdef",2,4)     result = "bcde"
PHP String sections
	substr("abcdef",0,3);     result = "abc"
	substr("abcdef",-2);      result = "ef"
	substr("abcdef",2);       result = "cdef"
	substr("abcdef",1,4);     result = "bcde"
ASP String search forward, reverse
Instr(), InstrRev()
	x=Instr("abcdef","de")        x=4 
	x=InstrRev("alabama","a")     x=7
PHP String search forward, reverse
strpos(), strrpos()
	$x=strpos("abcdef","de");      x=3
	$x=strrpos("alabama","a");     x=6
ASP String replace
Replace(string exp,search,replace)

PHP String replace
str_replace(search,replace,string exp)

$temp=str_replace("orange","apple",$temp); $temp=str_replace("'","\\'",$temp);
ASP, split a string into an array
PHP, split a string into an array
ASP, convert ASCII to String
x=Chr(65) x="A"
PHP, convert ASCII to String
$x=chr(65); x="A"
ASP, convert String to ASCII
x=Asc("A") x=65
PHP, convert String to ASCII
$x=ord("A") x=65
HTTP Environment
GET, POST and other variables:
Other variables:
@$_GET["name"]     (@ = ignore errors)
ASP, Server variables
PHP, Server variables
	@$_SERVER["HTTP_REFERER"];     @ = ignore errors
ASP Page redirects
PHP Page redirects
header("Location: wrong_link.htm");
ASP, prevent page caching
Response.AddHeader "pragma","no-cache"
PHP, prevent page caching
header("Cache-Control: no-store, no-cache");
header("Pragma: no-cache");
ASP, Limit script execution time, in seconds
PHP, Limit script execution time, in seconds
ASP, Timing script execution
	...ASP script to be timed...
	response.write duration & " seconds"
PHP, Timing script execution
	...PHP script to be timed...
	echo $duration." seconds";
	//required function
	function microtime_diff($a,$b) {
	list($a_dec,$a_sec)=explode(" ",$a);
	list($b_dec,$b_sec)=explode(" ",$b);
	return $b_sec-$a_sec+$b_dec-$a_dec;
File System Functions
ASP, create a file system object (second line is wrapped)
'Required for all file system functions
PHP, create a file system object
Not necessary in PHP
ASP, check if a file exists
PHP, check if a file exists
ASP, Read a text file
	xSize=xPage.Size  'Get size of file in bytes
	temp=xPage.Read(xSize)  'Read file
PHP, Read a text file
	$temp=file_get_contents($pFile);  //Read file
Time and Date Functions
ASP, Server Time or Date
Now, Date, Time
PHP, Server Time or Date
ASP, Date format (default)
Now = 6/29/2006 9:24:44 AM
Date = 6/29/2006
Time = 9:24:44 AM

Various ASP functions extract date parts:

Month(Date) = 6
MonthName(Month(Date)) = June
Day(Date) = 29
WeekdayName(Weekday(Date)) = Thursday
WeekdayName(Weekday(Date),False) = Thu
PHP, Date format
There is no default format in PHP.
The date() function is formatted using codes:

date("n/j/Y g:i:s A") = 6/29/2006 9:24:44 AM

date("n") = 6
date("F") = June
date("j") = 29
date("l") = Thursday
date("D") = Thu
Numeric Functions
ASP, convert decimal to integer

PHP, convert decimal to integer

ASP, determine if a value is numeric

if IsNumeric(n) then ...
PHP, determine if a value is numeric

if (is_numeric($num)) {...}
ASP, modulus function
x mod y
PHP, modulus function
$x % $y

PHP 4 to PHP 5 differences

PHP 5's major new achievements come in the area of its exception handling and a new object that introduces features that bring true OOP to PHP. Exception handling was certainly one of the most noticeable missing features in PHP 4, and its addition to PHP 5 is certainly a sign of maturity. Exception handling means you have language defined and standardized ways of handling errors in your software. Just use the try, catch, and throw methods, and your PHP code becomes more robust and clean.


class blue {

  function openFile ($inFile) {
    if (file_exists ($inFile)) {
      # code to open the file here
    } else {

      throw new Exception
	("Cannot open file: $inFile");

$blueObj = new blue ();

try {
  $blueObj->openFile ('/home/shull/file.txt');

} catch (Exception $myException) {
  echo $myException->getMessage ();

  # rest of exception handling code here


# rest of blue methods here


The new object model has a number of positive impacts on programs written in PHP. In PHP 4, when an object was passed to a function or method, it was passed by value, unless you explicitly told PHP otherwise. This procedure meant that a copy of that object, all the data structures in memory, would have to be copied. This step used memory and made access slow and clunky. In PHP 5, however, objects are always passed by reference.

The new object-oriented features in PHP 5, including constructors and destructors, are noteworthy. As with C++ and Java, they provide a standard way to create the object, allocate memory, and do any necessary setup via a constructor method and perform cleanup with a destructor method.

PHP 5 also introduces more subtle control of methods and variables in your classes. In PHP 4, everything was public: You could access variables from your classes outside the class or in derived classes. In PHP 5, you can still make variables or methods public, but you can also make them private, so they're used only within the class itself. A third option is to make them protected, which means that methods and variables can be viewed within the class or when subclassed.

Furthermore, PHP 5 introduces type hinting, or better type checking. When you pass an object into a routine, PHP can check that it is the right type and give a type-mismatch error if the check fails.

Additional features such as static methods and variables and abstract classes exist, so be sure to check the documentation for details.