Monday, November 29, 2010

Web Programming

There are too many ways to make dynamic Website, for example PHP, ASP.NET, AJAX, JSP.
People commonly use PHP or ASP.net as they tools to make a dynamic Website.

The differences between asp.net and PHP:





ASP.Net (VBScript)

PHP

General syntax



ASP.Net Comments
'this is comment


PHP Comments, inline
 
//This is comment   /*This is string in multiline */


ASP.Net, Escaping quotes
"" texbox1.text="saya adalah sebuah string"


PHP, Escaping quotes
\ $var="<img src=\"blank.gif\">";


ASP.Net Newline characters
vbCrLf textbox1.textmode=multiline textbox1.text="1" vbcrlf " 2 "


PHP Newline characters
"\n" (must be inside "", not '') echo "1 \n 2 ";


ASP.Net Variable Names
Not case sensitive, TEXT is the same as text


PHP Variable Names
Case sensitive AND must begin with $ so $text is NOT the same as $TEXT

String Functions



ASP.Net String length
Len() n=Len(plaintext)


PHP String length
strlen() $n=strlen($plaintext);


ASP.Net String concatenation
& textbox1.text=var1 & " " & var2 txtmsg.text=txtemsg & "information"


PHP String concatenation
. and .= $teks=$teks1." ".$teks2; $msgtext.="information";


ASP.Net, Change case
LCase(), UCase() lowerteks=LCase(TEKS) upperteks=UCase(teks)


PHP, Change case
strtolower(), strtoupper() $teks=strtolower($TEKSUPPER); $TEKS=strtoupper($tekslower);


ASP.Net Trim whitespace
Trim(),ltrim(),rtrim() text=Trim(xpage)


PHP, Trim whitespace
trim() and also ltrim(), rtrim() $text=trim($xpage);


ASP.Net String sections
Left(), Right(), Mid() Left("abcdef",3)    result = "abc" Right("abcdef",2)    result = "ef" Mid("abcdef",2,4)    result = "bcde"


PHP String sections
substr() substr("abcdef",0,3);    result = "abc" substr("abcdef",-2);    result = "ef" substr("abcdef",1,4);    result = "bcde"


ASP.Net 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.Net String replace
Replace(string exp,search,replace) text=Replace(text,"orange","apple") text=Replace(text,"'","\'")


PHP String replace
str_replace(search,replace,string exp) $text=str_replace("orange", "apple",$text); $text=str_replace("'","\\'",$text);


ASP.Net split a string into an array
Split() view="house,apartment,mess" asset=Split(view,",",-1,1) x=asset(0)


PHP, split a string into an array
explode() $view="house,apartment,mess,motell"; $asset=explode(",",$view); $x=$asset[0];

ASP.Net convert ASCII to String
x=Chr(65)     x="A"

PHP, convert ASCII to String
$x=chr(65);     x="A"


ASP.Net convert String to ASCII
x=Asc("A")     x=65

PHP, convert String to ASCII
$x=ord("A")     x=65

Control Structures



ASP.NET, if statements
if x>100 then    x=x+1 elseif x=100 then    x=x+2 else    x=x+3 end if

PHP, if statements
if ($x>100) {    $x=$x++; } else if ($x==100) {    $x=$x+2; } else {    $x=$x+3; }


ASP.Net, 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.Net, 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.Net, branching
select case status case "admin"   salutation="Welcome Admin" case "member"   salutation="Welcome Member" case "staff"   salutation="Welcome Staff" case else   salutation="Log in Please" end select txtsalutation.text=salutation


PHP, branching
switch ($status) { case "admin":   $salutation="Welcome Admin";   break; case "member":   $salutation="Welcome member";   break; case "employee":   $salutation="Welcome member";   break; default:   $salutation="login please"; } Echo $salutation;


ASP.Net functions
Function square(x)   myFunction = x*x   return myfunction End Function


PHP functions
function square($x) { return $x*$x; //Return value }

HTTP Environment



ASP.Net Page redirects
Response.redirect ("index.html")


PHP Page redirects
header("Location: index.htm ");l


ASP.Net , GET and POST variables
Request.QueryString("chat") Request.Form("username")


PHP, GET and POST variables
@$_GET["chat"];       @ = ignore errors @$_POST["username"];


ASP.Net, Limit script execution time, in seconds
Server.ScriptTimeout(240)


PHP, Limit script execution time, in seconds
set_time_limit(240);

File System Functions



ASP.Net, 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.Net, 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.Net, 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.Net, Server Time or Date
Now, Date, Time


PHP, Server Time or Date
date()




ASP.Net, Date format (default)
Now = 11/8/2010 6:11:16 AM Date = 11/8/2010 Time = 6:11:16 AM Various ASP functions extract date parts: Month(Date) = 11 MonthName(Month(Date)) = November Day(Date) = 8 WeekdayName(Weekday(Date)) = Monday WeekdayName(Weekday(Date),False) = Mon


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") = 11/8/2010 6:11:16 AM date("n") = 11 date("F") = November date("j") = 8 date("l") = Monday date("D") = Mon

Numeric Functions



ASP.Net, convert decimal to integer
Int() n=Int(x)


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


ASP.Net, 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.Net, modulus function
x mod y


PHP, modulus function
$x % $y


ASP.Net, hexa to decimal function
x=convert. toint32(hexa_numeric,16)


PHP, hexa to decimal function
$x=hecdec($hexa_numeric)


ASP.Net, decimal to hexa function
x=hex(hexa_numeric)


PHP, decimal to hexa function
$x=hecdec($hexa_numeric)










Links:



 





You can use this coding to convert from ASP.Net to PHP or PHP to ASP.Net.



You can use the visual studio in making ASP.Net Website and dreamweaver to making php

2 comments:

web programming