Differences between PHP and ASP.NET

Posted Sunday, March 21, 2004 2:48 PM by CumpsD
In response to a thread on the ASP.NET Forums I decided to publish the answers in an overview on my blog.

Someone asked on what the difference were between PHP and ASP.NET and how he did certain things.

My answers are based on using C# as the language for your ASP.NET application.

__________________________________


1. Is there any difference between '' and "" in ASP.NET?

Yes, ' ' is used for characters while " " is for strings.

Take this for example:
'a' = a in memory
"a" = a and \0 in memory

Something usefull about escaping in ASP.NET is the following:
@"bla\bla" == "bla\\bla"

A string with an @ in front of it is seen as a literal, where you don't have to escape special characters.


2. How would I do something like: print $variable.'string'; in ASP.NET?

You would use the following: Response.Write(variable + "string");
But it isn't very recommended to use Response.Write, take a look at all the server controls you have, like a Label for example.


3. Within an if language construct, what would be the equivalent of "and" and "or?"

Actually PHP supports the same being used in ASP.NET:

and --> &&
or --> ||

Example:

if (((number == 5) && (number2 != 8)) || (admin == true)) {

      // do stuff

}


Would correspond to:
if (number = 5 AND number2 NOT equal to 8 ) OR we're an admin., do stuff.


4. Would someone be able to tell me how I could make an ASP.NET equivalent of this PHP Function:

function num($number){
        return '#' . str_pad($number, 3, '0', STR_PAD_LEFT);
}


You need a function which returns a string, and which formats a string:

public string num(int number) {

      return String.Format("#{0}", number.ToString("000"));

}



5. How do I create a mutidimensional array?

Try this:

// 2 dimensional arrays

int [,] a1;

a1 = new int[3,2];

int [,] a2 = {{1,2}, {3,4}, {5,6}};

 

// jagged arrays

int[][] a3;

a3 = new int[3][];

a3[0] = new int[5]{1, 2, 3, 4 ,5};

a3[1] = new int[3];

a3[2] = new int[4]{21, 22, 23, 24};

Loop over them to see the elements.

__________________________________

Got a question yourself? Ask it, and I'll try to help :)

Filed under: ,

Comments

# re: Differences between PHP and ASP.NET

Sunday, March 21, 2004 11:45 AM by Gareth

Sorry, where's the asp.net?

# Take Outs for 21 March 2004.

Sunday, March 21, 2004 1:23 PM by TrackBack

Take Outs for 21 March 2004.

# re: Differences between PHP and ASP.NET

Sunday, March 21, 2004 2:40 PM by David Cumps

ASP.NET is just a 'platform', you have an ASP.NET application. You can use C#, VB.NET, COBOL.NET in your ASP.NET app, here I'm using C#. So it would make sense to explain basics C#.

PHP is a language, ASP.NET isn't. This person wanted to switch from PHP to ASP.NET using C#, so the answers to his questions made it possibile to create an ASP.NET app with C#. It's a very basic comparision between how you do something in PHP, and how you would do it using C# (in creating an ASP.NET app)

But yes, my mind was set on the ASP.NET because it was a reply in the Getting Started part of the ASP.NET Forums. But you could classify it under basic C# as well.

# re: Differences between PHP and ASP.NET

Sunday, March 21, 2004 5:57 PM by Jerry Pisk

String literals starting with @ are not string where you don't have to escape special characters, they are strings where you can't escape those. Don't have to would mean that you can, but don't have to if you don't want to but that's not how @ strings work. @ just ignore standard escape sequences, \ is considered a literal \ character, not an escape sequence mark. You cannot use escape sequences at all in @ strings. If you want to include a new line character in your string you can't use @ literal.

# re: Differences between PHP and ASP.NET

Sunday, March 21, 2004 11:43 PM by Justin Rogers

Strings are not stored the way you mention in your post. They are specifically stored with at least an array length, string length, and an array of WCHAR. ArrayLength can be larger than StringLength and there is a null terminating character applied to the end, so at least that much was correct. Strings have far more overhead than a simple extra WCHAR....

DWORD m_ArrayLength;
DWORD m_StringLength;
WCHAR m_Characters[0];

# re: Differences between PHP and ASP.NET

Monday, March 22, 2004 7:39 AM by David Cumps

Jerry Pisk: That's what I ment, yes. I'm not a native English speaker, but I did mention it was seen as a literal and without escaping. :)

Justin Rogers: Ok, didn't knew all of that. Only wanted to make clear that a string is different from a char, and with all the extra info you gave it's even more obvious :)

# re: Differences between PHP and ASP.NET

Monday, March 22, 2004 2:01 PM by Bertg

php,
you can fit "anything" in a var..
string, int, char :)

C#
a var can only contain one type of data-struct, no?

# re: Differences between PHP and ASP.NET

Monday, March 22, 2004 2:09 PM by David Cumps

That's what ment by loosly typed vs strongly typed.

C# is strongly typed, everything is of a certain type.

In php it's loosly, it can be anything as you say. Just like VB6 supports the Variant type and also doesn't require to declare variables (when you work with Option Strict)

# re: Differences between PHP and ASP.NET

Friday, April 20, 2007 12:05 PM by Fatima

so ... is there functionality difference between asp and php, I mean is there something which another cannot do?

# re: Differences between PHP and ASP.NET

Saturday, April 21, 2007 8:41 AM by CumpsD

If you set your mind to it and search long enough, I'd say you could do most of the things you want with any of both.

# re: Differences between PHP and ASP.NET

Monday, August 06, 2007 9:27 AM by arvind

there is alot of diffrence between PHP and ASP.

1. Cost wise(microsoft product) licence required.

2.speed.

3.platform compatibility.

4.additional cost if use the tools in the asp.

5.Base langauge.

6.database connectivity.

etc.

# re: Differences between PHP and ASP.NET

Tuesday, September 25, 2007 6:04 AM by jeeva

PHP is scripting Language but ASP.NET is Designing Tool.ASP.Net has a lot of controls to designing process bur PHP contains only scripting tabs and minimum no.of controls are used.

# Week Eleven Class Eleven « IMD 402’s Designing for Server Side Technologies

Pingback from  Week Eleven Class Eleven « IMD 402’s Designing for Server Side Technologies