General syntax
`my dog has fleas
//my dog has fleas
not available?
/* The quick brown fox jumped over the lazy dogs.*/
"""var text1="" "";"
\" or use ` like javascript`var text1=" ";`;
None, but only one command per line.
Each command must end with ; but multiple commands per line are allowed.
response.write "hello"
echo "hello";
vbCrLfresponse.write "hello" & vbCrLf
"\n" (must be inside "", not ``)echo "hello \n";
Not case sensitive, so fName is the same as FNAME
Case sensitive AND must begin with $so $fName is NOT the same as $FNAME
String Functions
&fname=name1 & " " & name2emsg=emsg & "error!"
. and .=$fname=$name1." ".$name2;$emsg.="error!";
LCase(), UCase()lowerName=LCase(chatName)upperName=UCase(chatName)
strtolower(), strtoupper()$lowerName=strtolower($chatName);$upperName=strtoupper($chatName);
Len()n=Len(chatName)
strlen()$n=strlen($chatName);
Trim()temp=Trim(xpage)
trim() and also ltrim(), rtrim()$temp=trim($xpage);
Left(), Right(), Mid()Left("abcdef",3)result = "abc"Right("abcdef",2) result ="ef"Mid("abcdef",3) result ="cdef"Mid("abcdef",2,4) result ="bcde"
substr()substr("abcdef",0,3); result ="abc"substr("abcdef",-2); result ="ef"substr("abcdef",2); result ="cdef"substr("abcdef",1,4); result ="bcde"
Instr(),InstrRev()x=Instr("abcdef","de") x=4x=InstrRev("alabama","a")x=7
strpos(),strrpos()$x=strpos("abcdef","de");x=3$x=strrpos("alabama","a");x=6
Replace(string exp,search,replace)temp=Replace(temp,"orange","apple")temp=Replace(temp,"`","\`")temp=Replace(temp,"""","\""")
str_replace(search,replace,string exp)$temp=str_replace("orange","apple",$temp); $temp=str_replace("`","\\`",$temp);$temp=str_replace("\"","\\\"",$temp);
Split()temp="cows,horses,chickens"farm=Split(temp,",",-1,1)x=farm(0)
explode()$temp="cows,horses,chickens";$farm=explode(",",$temp);$x=$farm[0];
x=Chr(65) x="A"
$x=chr(65); x="A"
x=Asc("A") x=65
$x=ord("A") x=65
Control Structures
if x=100 then x=x+5 elseif x<200then x=x+2 else x=x+1 endif
if ($x==100) { $x=$x+5; }else if ($x<200) { $x=$x+2; }else { $x++;}
for x=0 to 100 step 2 if x>p then exitfornext
for ($x=0; $x<=100; $x+=2) { if($x>$p) {break;}}
do while x<100 x=x+1 ifx>p then exit doloop
while ($x<100) { $x++; if($x>$p) {break;}}
select case chartName case "TopSales"theTitle="Best Sellers" theClass="S" case"TopSingles" theTitle="Singles Chart"theClass="S" case "TopAlbums" theTitle="AlbumChart" theClass="A" case elsetheTitle="Not Found"endselect
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="NotFound";}
Function myFunction(x) myFunction = x*16 `ReturnvalueEnd Function
function myFunction($x) { return $x*16; //Returnvalue}
HTTP Environment
Request.ServerVariables("SERVER_NAME")Request.ServerVariables("SCRIPT_NAME")Request.ServerVariables("HTTP_USER_AGENT")Request.ServerVariables("REMOTE_ADDR")Request.ServerVariables("HTTP_REFERER")
$_SERVER["HTTP_HOST"];$_SERVER["PHP_SELF"];$_SERVER["HTTP_USER_AGENT"];$_SERVER["REMOTE_ADDR"];@$_SERVER["HTTP_REFERER"];@ = ignore errors
Response.redirect("wrong_link.htm")
header("Location: wrong_link.htm");
Request.QueryString("chat")Request.Form("username")
@$_GET["chat"]; @ = ignore errors@$_POST["username"];
Response.CacheControl="no-cache"Response.AddHeader "pragma","no-cache"
header("Cache-Control: no-store, no-cache");header("Pragma: no-cache");
Server.ScriptTimeout(240)
set_time_limit(240);
s_t=timer ...ASP script to betimed...duration=timer-s_tresponse.writeduration &" seconds"
$s_t=microtime();...PHP script to betimed...$duration=microtime_diff($s_t,microtime());$duration=sprintf("%0.3f",$duration);echo$duration." seconds"; //requiredfunctionfunction 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
`Required for all file system functionsfileObj=Server.CreateObject ("Scripting.FileSystemObject")
Not necessary in PHP
pFile="data.txt"fileObj.FileExists(Server.MapPath(pFile))
$pFile="data.txt";file_exists($pFile);
pFile="data.txt"xPage=fileObj.GetFile(Server.MapPath(pFile))xSize=xPage.Size`Get size of file inbytesxPage=fileObj.OpenTextFile(Server.MapPath(pFile))temp=xPage.Read(xSize)`Read filelinkPage.Close
$pFile="data.txt";$temp=file_get_contents($pFile);//Read file
Time and Date Functions
Now, Date, Time
date()
Now = 7/10/2007 4:35:06 AMDate = 7/10/2007Time = 4:35:06 AMVarious ASP functions extract date parts:Month(Date) = 7MonthName(Month(Date)) = JulyDay(Date) = 10WeekdayName(Weekday(Date)) = TuesdayWeekdayName(Weekday(Date),False) = Tue
There is no default format in PHP. The date() function is formatted using codes:date("n/j/Y g:i:s A") = 7/10/2007 4:35:06 AMdate("n") = 7date("F") = Julydate("j") = 10date("l") = Tuesdaydate("D") = Tue
Numeric Functions
Int()n=Int(x)
floor()$n=floor($x);
IsNumeric()if IsNumeric(n) then ...
is_numeric()if (is_numeric($num)) {...}
x mod y
$x % $y