ASP / PHP Cross Reference

v1.0, 2008-02-01

This is by no means a complete list but it should help you convert ASP to PHP or the other way around. PHP has many more built in commands than ASP (VBScript), so several lines of code in ASP may convert so a single line in PHP. If you have a large application to move from ASP to PHP, the ASP Translator is a free web application that will save you hours of work. It converts comments, variables, if/then, loops, and many commands from ASP to PHP, all in your web browser.



On small screens, the table scrolls -->

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";
}
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
Response.redirect("wrong_link.htm")
PHP Page redirects
header("Location: wrong_link.htm");
ASP, GET and POST variables
Request.QueryString("chat")
Request.Form("username")
PHP, GET and POST variables
@$_GET["chat"];       @ = ignore errors
@$_POST["username"];
ASP, prevent page caching
Response.CacheControl="no-cache"
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
Server.ScriptTimeout(240)
PHP, Limit script execution time, in seconds
set_time_limit(240);
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
fileObj=Server.CreateObject
 ("Scripting.FileSystemObject")
PHP, create a file system object
Not necessary in PHP
ASP, check if a file exists
pFile="data.txt"
fileObj.FileExists(Server.MapPath(pFile))
PHP, check if a file exists
$pFile="data.txt";
file_exists($pFile);
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
Now, Date, Time
PHP, Server Time or Date
date()
ASP, Date format (default)
Now = 6/30/2012 6:14:53 AM
Date = 6/30/2012
Time = 6:14:53 AM

Various ASP functions extract date parts:

Month(Date) = 6
MonthName(Month(Date)) = June
Day(Date) = 30
WeekdayName(Weekday(Date)) = Saturday
WeekdayName(Weekday(Date),False) = Sat
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/30/2012 6:14:53 AM

date("n") = 6
date("F") = June
date("j") = 30
date("l") = Saturday
date("D") = Sat

Numeric Functions

ASP, convert decimal to integer
Int()

n=Int(x)
PHP, convert decimal to integer
floor()

$n=floor($x);
ASP, determine if a value is numeric
IsNumeric()

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

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


Links:



ADD A COMMENT



[74 Comments]


  

Gracias

23 Oct 2015 9:11am

"Tengo tu página en mis favoritos, actualmente estoy convirtiendo un sitio de asp a php y tu guía me ayuda mucho! Gracias!!! Saludos desde México :)"
 


  

Gracias!

06 Feb 2015 11:45am

"Utilizo ésta referencia todos los días ya que me encuentro trabajando en cambiar un sistema de asp a php y realmente me es muy util! Gracias!!! Saludos desde México :)

I use this reference daily since I'm working on changing a system to php [from] asp and really is very useful! Thank you!!! Greetings from Mexico :)"
 


  

Great Stuff !!!

05 Aug 2013 7:03pm

"Thanks... i've interview and thought of refreshing the ASP vbscript syntax and key words ..The page is really helpful !!!"
 


  

oscar

29 May 2013 11:36am

"Thanks, thanks, thanks!! great!"
 


  

grinder

24 May 2013 10:38am

"2013 and this reference is still awesome. Thanks!"
 


  

Awesome Resource

20 Feb 2012 6:17am

"Great resource. Thanks for making it available and sharing."
 


  

Manuel

28 Jan 2012 7:17am

"Cool page!!! Thanks a lot!"
 


  

Tony

09 Dec 2011 2:45am

"Well done good sir! I use this so often now, thanks for putting it together for us!"
 


  

from programmer NPC

12 Jul 2011 3:48pm

"Long-time PHP/Python programmer here, taking on now the first project where I have to use ASP (VB) due to the company's current enterprise software. I had never seen ASP in any detail before so this has been interesting... anyway, poking around online for this and that separately has its limits... just found this, and THANKS!! Basically everything I need, right here, searching done. The direct comparisons to PHP are going to speed my project along a lot. Bookmarked immediately."
 


  

Monski

10 Feb 2011 1:05am

"wow!!! this is awesome page... hope u still add more function.. like it."
 


  

BacklinkFinder

26 Nov 2010 10:46pm

"that's a very interesting and useful subject in this page, i search about curl that i hope to find translated to the classic ASP, but no result. Nice page, Thanks"
 


  

RMB

21 Oct 2010 6:20am

"The PHP side of your timing script can be re-written much more simply. PHP's microtime() function will return a float representing epoch seconds down to a bunch of decimal places if you give it a true value for its first parameter. Here it is:

$s_t = microtime(true);

...PHP script to be timed...

$duration = microtime(true) - $s_t;
echo sprintf("%0.3f seconds",$duration);"
 


  

Joebuntu

02 Aug 2010 11:11am

"Superb. Im working now for a company and has old pages made on ASP and i know PHP, this helped me a lot. Thank you so much."
 


  

Bard

14 Jul 2010 11:51am

"great reference! I am an ASP expert but know little about PHP and my new job requires PHP. Thanks for putting this up (and leaving it up for 4 years or so I guess now)."
 


  

peter

02 Jul 2010 6:34am

"Great and useful work! thanks a lot."
 


  

Tanmay

27 Apr 2010 3:00am

"Good comparison. A person who has experience in ASP can have a little info about PHP and a person with knowledge of PHP can get basic info about ASP."
 


  

Amper

25 Apr 2010 11:38pm

"Great to find this ref I am sick of the propeller heads at MS sticking OOP in our faces at every turn. I understand in .exe files and large programming projects with unlimited budgets, OOP and OOA is fine. I just don't get OOP on the web. Talk about losing the market or being out of touch with the user base. .Net is bloated and slow. This could be the end of MS in the OS world. I mean, when people find out that Linux is free... PHP here I come. Amper"
 


  

Rob

16 Mar 2010 9:51am

"Thank you, Excellent page for switching from ASP to PHP"
 


  

Phillipe Calmet

03 Dec 2009 10:48am

"Thanks for sharing this. This definitely very useful :D"
 


  

Thank you

03 Dec 2009 8:58am

"Thanks. I am required to convert a site I developed in PHP into asp by "yesterday" and I have NO experience of ASP. I found this reference today after a marathon 14 hour stint yesterday and you have saved me so much time today. My heartfelt thanks!"
 


  

Dave M

20 Nov 2009 12:44pm

"Nice. tnx for you work!!"
 


  

AMP

25 Jun 2009 9:58am

"Thank you so much for taking the time and effort to put out such a fine cross reference for asp and php."
 


  

Andrew

31 Mar 2009 5:04am

"Excellent page! I started to code a program in VB6, and decided to use PHP instead, so this is very useful for quickly changing the code. I have several years PHP experience, but I haven't worked with it in almost a year, so I'm a bit rusty. FYI, the curly braces are only necessary for multiple statements in a block, they're not needed for single statements."
 


  

ASP IF alternative syntax?

19 Mar 2009 12:28am

"Great Cross Reference, thanks! Very helpful. BTW, would you know the ASP equivalent syntax for the PHP alternative IF statement? Here is an example: $var = $a == 1 ? 'ok' : 'ko'; Cheers and thanks! Aaron"
 


  

CAR

23 Feb 2009 6:12am

"For converting to an integer, there's also the intval() function in PHP."
 


  

David Eldridge

18 Feb 2009 4:03am

"Thanks so much for this succinct reference."
 


  

Divu

15 Dec 2008 12:21am

"Thanks a ton..."
 


  

Coto

26 Nov 2008 5:32am

"Thanks... thanks... only thanks :-D"
 


  

functionifelse

15 Nov 2008 8:51pm

"php also supports # as a single line comment"
 


  

Wonderfull

14 Nov 2008 5:06am

"Good article man. Very good and very easy. Thanks."
 


  

Rhys

10 Oct 2008 6:25am

"great site,this site will come in handy. you could add
ASP: x=createobect("myobject.myclass") y=x.myfunction
PHP: $x=new com("myobject.myclass") $y=$x->myfunction();"
 


  

Archana g

17 Sep 2008 10:23pm

"this article is gr8, its solves almost all problems of mine as i don't know any thing about asp. i have to convert asp code into php code"
 


  

Morten P

10 Sep 2008 2:15am

"Just found your site. Wow! Way to go, just the way to go. Thanks very much."
 


  

Anand

28 Aug 2008 2:52am

"I am basically a clipper/xbase++ guy. Though I know a little bit vb and vb.net, but have no idea on php or asp. I surfed and decided on php for my dynamic web design project, but again my friends suggested for asp. I was confused with merit/demerit of both. Your article has put forth both in crystal clear way. Since I know little bit vb, I could understand php codes now. I am very much grateful to you for this very needed information. I have decided on php now. Thanks a lot, Rob"
 


  

Daniel

14 Aug 2008 10:44am

"Repeating : freaking awesome, great stuff, excellent... Saved me a lot of time. Just added to my fav links. Thanks."
 


  

Gary P

05 Aug 2008 3:54pm

"Great reference! You could also add the VBscript IsDate() function and php equivalent. And maybe also the querystring comparisons? Plus, database connection code block? But you have the bones of everything else!

[reply from Robert Giordano]
I'll be adding those things soon! Thanks for the suggestions!!"
 


  

Glenn

30 Jul 2008 7:49am

"Awesome. I'm an ASP programmer and am looking into making the transition to PHP. This is a great start. Thanks very much."
 


  

John Cotter

24 Jul 2008 11:04pm

"fantastic idea, doing php for years, and need to do some asp now, perfect reference. 10/10. thanks"
 


  

IheartYou - Twist

09 Jul 2008 3:59pm

"OMFG this is SOOO freaking awesome. I program in both languages, and some things i cant do in the other language. This is so AMAZINGLY exactly what i needed. MUCH love."
 


  

Thanks nice reference!

28 May 2008 6:21am

"Thanks for this! With regards,
Thomas
Holland."
 


  

Emadz

28 May 2008 2:50am

"Excellent work! good effort for helping developers..."
 


  

Just what I was looking for

22 May 2008 6:04am

"This is such a useful reference. It's made my job so much easier. Thanks"
 


  

Guillermo

18 Apr 2008 5:30am

"muy buena la guia. Muchas Gracias"
 


  

Fantastic !!!!

07 Mar 2008 11:17pm

"really nice...... very helpful for us, thnxxxxxx a lots"
 


  

Application, Session, Includes

03 Mar 2008 4:54pm

"Been doing ASP for about 10 years,.Net for the past few, but we might move to PHP, so this is really cool. For the heckuvit, I'd love to see an overview on if PHP has anything comparable to Session or Application. And also (although it's IIS not ASP), details on any sort of #include functionality offered by PHP. I know there is some type of include and also a virtual function, but I'd love to know details on variable/function visibility from page to include, include to include, or nested.

[Reply from Robert Giordano]
PHP has support for both sessions and includes. I'll add that information to the chart at some point, but it gets a little complex so its probably best to see the full documentation on php.net."
 


  

Superb! BIG thank you!

18 Feb 2008 1:00am

"This was really useful. Exactly what i wanted. Being an ASP mind made me hard to handle PHP. This cross reference will help me to work with PHP although I am ASP minded. Got my point? I can work vice-versa without any fear of getting confused or being a mess! Again BIG thank you to the author."
 


  

Great comparision

19 Nov 2007 8:05am

"Hai... really it's very great stuff. Shaik Amjad"
 


  

Fantastic time saver

14 Nov 2007 6:35am

"Saved me a bunch of time converting a stack of ASP pages into PHP. Thanks!"
 


  

Tomas

03 Nov 2007 3:19pm

"Really Useful. Congratulations and Thank you very much"
 


  

Good one for learner

02 Nov 2007 12:11am

"Hi. This is really good for those who know one language and are learning other one. Thanks design215"
 


  

iDude

25 Oct 2007 12:43pm

"I use this website almost every day @ work to convert my old ASP/VB apps over to PHP. It has helped me greatly as a quick reference. Expanding the list a little and/or perhaps allowing people to submit entries (for approval) would be nice. Keep up the good work!

[Reply from Robert Giordano]
Thanks! Submit entries here in the comments and I'll review them and add them."
 


  

Leo Todeschini

09 Oct 2007 5:59pm

"Great job, I develop in both languages but this piece of info is really relevant and helpful. Thanks a lot! Asap I'll be adding something like this on my blog, loved the idea (of course I'll give you the proper credits). Keep the nice work buddy. C-ya"
 


  

lokesh yadav

05 Oct 2007 12:25am

"solved my all problems, so thanks"
 


  

ASP Command Separator

03 Oct 2007 1:09pm

"FYI, statements (referred to in the reference as commands) in VB/VBA/VBScript may be separated with a statement terminator represented by the colon. For example, the following is acceptable and can be used to combine multiple statements on a single line of the source file, if desired: Dim s1: s1 = "Value1": Dim s2: s2 = "Value2" Please correct the reference with this information. Don't take my word for it. Try it with a VBScript, VBA code module, and an ASP page served up by IIS.

[Reply from Robert Giordano]
Thanks for the information. IMHO I don't think its good programming style to have multiple statements on one line. I've noticed a number of things in ASP/VB that I feel make for sloppy programming, such as not honoring the case of variable names. I believe code is art and so I try to write code that is beautiful. =)"
 


  

Awesome

09 Sep 2007 7:32am

"exactly what i needed for my assignment! thanks for this"
 


  

Victor

17 Aug 2007 7:52am

"Muito bom o guia!! Eu vou mecher justamente com as duas linguagens e as vezes fico perdido com as diferenas! Valeu!!!"
 


  

Great work, Thanks a LOT !!!

16 Jul 2007 6:09am

"Really nice to have this reference!! Thanks a lot!"
 


  

thanks - very helpful

02 Jul 2007 6:34am

"Thanks a lot - this is pretty helpful."
 


  

Tom Glenn

29 Jun 2007 2:15am

"Excellent article, will definitely help me a lot as I am originally a PHP programmer but my work requires me to use ASP. Thanks, and please do keep expanding!"
 


  

Alex Baskov

18 Jun 2007 5:56am

"great reference!"
 


  

ASP command termination

18 May 2007 5:15am

"Note that ASP commands can be terminated using a colon :, allowing multiple commands per line. seb @ sebsworld"
 


  

life saver

17 May 2007 9:22am

"i know i'm just repeating what everyone else has said before me, but this is a fantastic reference. i'm redeveloping a client's asp web app in php and you've just saved me about 3 days' worth of reading and cross referencing! this goes straight into FF bookmarks :)"
 


  

Ritesh

24 Apr 2007 2:12am

"hi. this is really useful for those who either know php or asp. thanks"
 


  

Brilliant!

06 Apr 2007 5:05am

"Very good idea too! Thanks a lot."
 


  

Keshpur Mamabari, this is good

30 Mar 2007 4:28am

"Hi, this is a very good cross reference"
 


  

Johan

01 Mar 2007 11:16pm

"great, you could add:
--------------
Session("foo") = "bar" /
session_start(); $_SESSION['foo'] = 'bar';
--------------"
 


  

Rodrigo Silva

01 Feb 2007 6:01am

"A great list, altought a little biased towards PHP. My comments: - For new line character, vbNewLine is recommended over vbCrLf. The latter works, and its widely used, but it is obsolete and platform dependent. vbNewLine is much more elegant and platform independent. Platform independence may be not so relevant in ASP, but since it uses VBScript that can run on Mac, Palmtops, etc, vbNewLine is recommended. It is the one used on ASP .NET too. - ASP DOES have LTrim and RTrim"
 


  

Really good!

23 Jan 2007 7:58am

"thanks!, this saved my life!"
 


  

abo-3ziz

18 Jan 2007 7:07am

"thank for these info. these will really help us in our project which will translate from PHP to ASP.NET with C#."
 


  

Small omission

14 Dec 2006 1:37pm

"Thanks for a really great reference. No need to add this to the comments, but just to let you know that ASP *does* have a command terminator : which allows more than one command on a line"
 


  

Reference

09 Nov 2006 10:28pm

"This is a really good cross reference and it is helping me a lot. Its help me as a newbie in PHP. thanks to the author."
 


  

What a good cross reference!!

18 Oct 2006 5:59am

"This is a really good cross reference and it is helping me a lot. It will help all those programmers who want to learn PHP and they know ASP. Very good and thanks to the author."
 


  

Sagar Sonker

16 Aug 2006 2:48am

"Excellent piece of info. I was searching for new line character in ASP, and found much more on this website... :)"
 


  

Wonderful.

13 Jun 2006 11:49am

"This is an extremely helpful cross-reference. The only other thing I think you could add would be database functions like mysql_num_rows() (PHP) and the equivalent of while looping as related to $row["colname"] vs. connection.fields("colname") Keep expanding this! It'll make it so much easier for developers like myself to continue developing solid applications. Great work."