ASP/PHP referenčna lista ni ravno popolna, ampak bo zadovoljila večino potreb pri pretvarjanju ASP v PHP ali obratno. Ker ima PHP že veliko “vgrajenih” ukazov se bo velikokrat več vrstic ASP kode spremenilo v samo eno vrstico PHP kode.
ASP (VBScript)
|
PHP (v4.3+)
|
General syntax | |
ASP Comments, inline
|
PHP Comments, inline
|
ASP Comments, blocknot available?
|
PHP Comments, block
|
ASP, Escaping quotes
"var text1=""<img src=\""blank.gif\"">"";"
|
PHP, Escaping quotes
\" or use
'var text1="<img src=\"blank.gif\">";';
|
ASP Command termination
|
PHP Command termination
|
ASP Screen output
|
PHP Screen output
|
ASP Newline characters
response.write "hello" & vbCrLf
|
PHP Newline characters
echo "hello \n";
(must be inside “”, not ”) |
ASP Variable Names
so fName is the same as FNAME
|
PHP Variable Names
|
String Functions | |
ASP String concatenation
fname=name1 & " " & name2
|
PHP String concatenation
$fname=$name1." ".$name2;
|
ASP, Change case
LCase(), UCase()
upperName=UCase(chatName)
|
PHP, Change case
$lowerName=strtolower($chatName);
|
ASP String length
n=Len(chatName)
|
PHP String length
$n=strlen($chatName);
|
ASP, Trim whitespace
temp=Trim(xpage)
|
PHP, Trim whitespace
$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
temp=Replace(temp,"orange","apple")
temp=Replace(temp,"""","\""")
search,replace) |
PHP String replace
$temp=str_replace("orange","apple",$temp);
(search,replace,string exp) |
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
|
PHP, convert ASCII to String
$x=chr(65); x="A"
|
ASP, convert String to ASCII
|
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"; } |
ASP functions
Function myFunction(x) myFunction = x*16 'Return value End Function |
PHP functions
function myFunction($x) { return $x*16; //Return value } |
HTTP Environment | |
ASP, Server variables
Request.ServerVariables("SERVER_NAME") Request.ServerVariables("SCRIPT_NAME") Request.ServerVariables("HTTP_USER_AGENT") Request.ServerVariables("REMOTE_ADDR") Request.ServerVariables("HTTP_REFERER") |
PHP, Server variables
$_SERVER["HTTP_HOST"]; $_SERVER["PHP_SELF"]; $_SERVER["HTTP_USER_AGENT"]; $_SERVER["REMOTE_ADDR"]; @$_SERVER["HTTP_REFERER"]; @ = ignore errors |
ASP Page redirects
|
PHP Page redirects
header("Location: wrong_link.htm");
|
ASP, GET and POST variables
|
PHP, GET and POST variables
@$_POST["username"];
|
ASP, prevent page caching
Response.AddHeader "pragma","no-cache"
Response.CacheControl=”no-cache” |
PHP, prevent page caching
|
ASP, Limit script execution time, in seconds
|
PHP, Limit script execution time, in seconds
|
ASP, Timing script execution
s_t=timer ...ASP script to be timed... duration=timer-s_t response.write duration &" seconds" |
PHP, Timing script execution
$s_t=microtime(); ...PHP script to be timed... $duration=microtime_diff($s_t,microtime()); $duration=sprintf("%0.3f",$duration); 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
("Scripting.FileSystemObject")
|
PHP, create a file system object
|
ASP, check if a file exists
|
PHP, check if a file exists
|
ASP, Read a text file
pFile="data.txt" xPage=fileObj.GetFile(Server.MapPath(pFile)) xSize=xPage.Size 'Get size of file in bytes xPage=fileObj. OpenTextFile(Server.MapPath(pFile)) temp=xPage.Read(xSize) 'Read file linkPage.Close |
PHP, Read a text file
$pFile="data.txt"; $temp=file_get_contents($pFile); //Read file |
Time and Date Functions | |
ASP, Server Time or Date
|
PHP, Server Time or Date
|
ASP, Date format (default)
Time = 6:58:29 PM
Month(Date) = 1 MonthName(Month(Date)) = January Day(Date) = 20 WeekdayName(Weekday(Date)) = Wednesday WeekdayName(Weekday(Date),False) = Wed
Date = 1/20/2010 |
PHP, Date format
The date() function is formatted
date("n/j/Y g:i:s A") = 1/20/2010 6:58:29 PM date("n") = 1 date("F") = January date("j") = 20 date("l") = Wednesday date("D") = Wed
format in PHP. |
Numeric Functions | |
ASP, convert decimal to integer
n=Int(x)
|
PHP, convert decimal to integer
$n=floor($x);
|
ASP, determine if a value is numeric
if IsNumeric(n) then ...
|
PHP, determine if a value is numeric
if (is_numeric($num)) {...}
is_numeric() |
ASP, modulus function
|
PHP, modulus function
|