| ASP (VBScript) |
PHP (v4.3+) |
|
General syntax
|
- ASP Comments, inline
'my dog has fleas |
- PHP Comments, inline
//my dog has fleas |
- ASP Comments, block
not available? |
- PHP Comments, block
/* The quick brown fox jumped over the lazy dogs. */ |
- ASP, Escaping quotes
"" "var text1=""<img src=\""blank.gif\"">"";" |
- PHP, Escaping quotes
\" or use ' like javascript 'var text1="<img src=\"blank.gif\">";'; |
- ASP Command termination
None, but : can be used to separate commands on the same line. |
- PHP Command termination
Each command must end with ; but multiple commands per line are allowed. |
- ASP Screen output
response.write "hello" |
- PHP Screen output
echo "hello"; |
- ASP Newline characters
vbCrLf response.write "hello" & vbCrLf |
- PHP Newline characters
"\n" (must be inside "", not '') echo "hello \n"; |
- ASP Variable Names
Not case sensitive, so fName is the same as FNAME |
- PHP Variable Names
Case sensitive AND must begin with $ so $fName is NOT the same as $FNAME |
|
String Functions
|
- ASP String concatenation
& fname=name1 & " " & name2 emsg=emsg & "error!" |
- PHP String concatenation
. and .= $fname=$name1." ".$name2; $emsg.="error!"; |
- ASP, Change case
LCase(), UCase() lowerName=LCase(chatName) upperName=UCase(chatName) |
- PHP, Change case
strtolower(), strtoupper() $lowerName=strtolower($chatName); $upperName=strtoupper($chatName); |
- ASP String length
Len() n=Len(chatName) |
- PHP String length
strlen() $n=strlen($chatName); |
- ASP, Trim whitespace
Trim() temp=Trim(xpage) |
- PHP, Trim whitespace
trim() and also ltrim(), rtrim() $temp=trim($xpage); |
- 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()
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) temp=Replace(temp,"orange","apple") temp=Replace(temp,"'","\'") temp=Replace(temp,"""","\""") |
- PHP String replace
str_replace(search,replace,string exp) $temp=str_replace("orange","apple",$temp); $temp=str_replace("'","\\'",$temp); $temp=str_replace("\"","\\\"",$temp); |
- ASP, split a string into an array
- Split()
temp="cows,horses,chickens" farm=Split(temp,",",-1,1) x=farm(0) |
- PHP, split a string into an array
- explode()
$temp="cows,horses,chickens"; $farm=explode(",",$temp); $x=$farm[0]; |
- 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 |
|
Control Structures
|
- ASP, if statements
- if x=100 then
x=x+5 elseif x<200 then x=x+2 else x=x+1 end if |
- PHP, if statements
- if ($x==100) {
$x=$x+5; } else if ($x<200) { $x=$x+2; } else { $x++; } |
- ASP, for loops
- for x=0 to 100 step 2
if x>p then exit for next |
- PHP, for loops
- for ($x=0; $x<=100; $x+=2) {
if ($x>$p) {break;} } |
- ASP, while loops
- do while x<100
x=x+1 if x>p then exit do loop |
- PHP, while loops
- while ($x<100) {
$x++; if ($x>$p) {break;} } |
- ASP, branching
- select case chartName
case "TopSales" theTitle="Best Sellers" theClass="S" case "TopSingles" theTitle="Singles Chart" theClass="S" case "TopAlbums" theTitle="Album Chart" theClass="A" case else theTitle="Not Found" end select |
- PHP, branching
- switch ($chartName) {
case "TopSales": $theTitle="Best Sellers"; $theClass="S"; break; case "TopSingles": $theTitle="Singles Chart"; $theClass="S"; break; case "TopAlbums": $theTitle="Album Chart"; $theClass="A"; break; default: $theTitle="Not Found"; } |