|
This is a summary of the language differences between PHP, JScript/Javascript and VBScript that I did to help my company learn the 3 server side scripting languages. Hope it's helpful to others. I started out as an ASP developer, and switched to PHP. I have been using ASP since 1998 (we continue to support our customers who are still using ASP), and PHP since 2000 (our main web development platform). In general, my experience with PHP has been very positive. Here are the nice things i found about PHP:
|
![]()
| Feature | PHP | JScript and Javascript | VBScript |
| Example (print 1 to 10 on a web page) |
<html> <body> <?php for ($i=1; $i<=10; $i++) |
<html> <body> <% for (i=1; i<=10; i++) |
<html> <body> <% for i = 1 to 10 Response.Write(i & "<br>") next %> </body></html> |
| Script Tags |
<?php ?> If short tags are enabled in PHP.ini: If ASP tags are enabled in PHP.ini: <%= return expression %> |
<% %> <%= return expression %> |
<% %> <%=return expression %> |
| End of statement | semicolon (;) is compulsory | End of line or optional semicolon | End of line |
| Comments |
// PHP comment 1 /* This is a multi-line Comment */ # PHP comment 3 |
// JScript comment
/* This is a multi-line Jscript Comment */ |
' VBScript comment |
| Variables | Prefixed by $ | No prefix | No prefix |
| Need to declare variables? |
No, and every variable is preinitialised to type NULL, which is equivalent to false, the empty string and 0. $AVAR = 123; |
Optional. Error if variable not initialised when used. var AVAR |
Optional. Error if variable not initialised when used. Dim AVAR |
| Loosely Typed Variables |
Yes. This means that the type of a variable can be changed at run-time. To change variable type, use typecasting or settype( ) |
Yes | Yes |
| Case-Sensitivity | Yes for variables, no for function-names and reserved words | Yes for variables and reserved words | No |
| Strings |
Delimited by single-quotes, double-quotes or PERL heredoc style. $avar = 'this is a string'; $avar = "this is a string"; $avar = <<<EOS this is a string EOS; |
Delimited by single-quotes or double-quotes. | Delimited by double-quotes. |
| String Concatenation |
The . (dot) symbol. $s = 'A' . 'B'; |
The + (plus) symbol. s = 'A' + 'B' |
The & (ampersand) symbol. s = "A" & "B" |
| String Evaluation |
Yes, variables embedded in strings are evaluated if string delimited by double-quotes. $a = "A"; |
No | No |
| Common string constants |
Line feed: "\n" Note that single-quoted 'n' is not converted to a line-feed for PHP. Only double-quoted strings are evaluated. |
Line feed: "\n" |
Line feed: vbLf |
| HTML encoding functions |
htmlspecialchars($str) Converts < > & and " to their HTML entity equivalents, eg. < becomes < urlencode( ) All punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding. Spaces converted to +. urldecode( )All punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding. Spaces converted to +. |
escape(str) All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding unescape(str) inverse of escape |
Requires ASP Server object (and consequent COM overhead). Server.HMTLEncode( ) Similar to PHP's htmlspecialchars. Server.URLEncode( ) Similar to PHP's urlencode.
|
| Regular Expressions |
Built-in. if (preg_match ("/php/i", $str)) |
Built-in. if (str.match(/php/i)) |
Use COM object RegExp. Only available with the latest versions of VBScript (5.5 or later). |
| Dates |
$adate = time(); $adate=mktime(0,0,0,1,30,2000); |
adate = new Date(); adate = new Date(2000,1,30) Dates are formated using the current locale configured in the control panel, so you have to hand-code date formatting or change your locale. |
adate = Now
date= CDate('2000-1-30')
FormatDateTime(adate,2)
Dates are formated using the current locale configured in the control panel, so you have to hand-code date formatting or change your locale. |
| Arrays |
Declare with For indexing use [ ]. Arrays begin with zero element. Use sizeof(array) function to get size of array. Arrays can be iterated over using: $val = reset($arr); $max = sizeof($arr); |
Declare with For indexing use [ ]. Arrays begin with zero element. Use array.length to get size of array. |
Declare with For indexing use ( ). Arrays begin with zero element.
|
| Associative Arrays |
Yes $avar = array(); $avar['newton']='isaac'; echo $avar['newton']; Note: You can append new elements to arrays with |
Yes avar = new Array(); avar['newton'] = 'isaac'; Response.Write(avar['newton']) |
Not built into the language, but can simulated using the Dictionary object (which is not thread-safe in VBScript 5.0). |
| True and False |
Has constants true and false. The following also evaluate to false: 0 /* zero */ "" /* empty string */ "0" /* string with zero */ |
Has constants true and false. Empty strings and zero will evaluate to false. |
Has constants true and false. Unlike PHP and JScript, zero does not evaluate to false. |
| Equality |
== true if equal != not equal Note that some functions can return 0 or false (false is typically used
to indicate failure) depending on the context. For these functions, you will
need to use === to determine whether 0 or false was returned. Some problematic
functions: strpos, strrpos, strstr,
stristr, strrchr |
== true if equal != not equal JScript does not have the 0/false problem. |
= true if equal <> not equal |
| Assignment statements |
Allows C style shortcut assignments. For example, to append a string to a variable: $avar .= 'append to end'; |
Allows C style shortcut assignments. For example, to append a string to a variable: avar += 'append to end'; |
No shortcut assignments. |
| Sending HTML to Browser | print $avar; echo "The avar variable '$avar' is a string"; |
Response.Write(avar); | Response.Write(avar); |
| If statements |
if (strlen($avar) == 0) {
$avar = "abc";
} else
|
Similar to PHP and C. |
if len(avar) = 0 then avar = "abc" else avar = avar & "end" |
| While statements |
while ($a > 0) {$a -= 1;}
|
while (a > 0) a -= 1; |
while a > 0 a = a - 1 wend |
| For loops |
for ($i=0,$m=9; $i<$m; $i++){
|
for (i=0,m=9; i<m; i++) {
Response.Write(i);
}
|
for i=1 to 100 Response.Write(i) next |
| Switch/Case |
switch($aColor) {
case 'red': do1;break;
case 'green': do2;break;
default: do3; break;
}
|
switch(aColor) {
case 'red':
do1
break
case 'green':
do2
break
default: do3; break;
}
|
select case aColor case "red" do1 case "green" do2 case else do3 end select |
Part 2 Functions, Classes
Part 3 ASP Objects and PHP

