Thursday, June 4, 2009

Advantages of php over asp and converting asp site into php site.


php is having many advantages over asp in terms of cost, Speed, Security and flexibility.

Refer below articles comparing asp and php.

http://www.webpronews.com/expertarticles/2005/12/22/asp-vs-php
http://www.netconcepts.com/php-versus-asp/

So, it will be useful if we convert any existing asp websites into php site.

Some converters are available to convert any asp website into php site.

You can download asp2php converter here. I haven't tried it yet.

Some online converters are also available to convert asp webpage into php pages.

Find below an online converter.
http://www.design215.com/toolbox/translator/index.php

If you want to manually convert the asp pages into php pages, you can follow below steps.

Conversion of asp to php.



In asp no need to put semicolon at the end of the each line, but semicolon required in php.
1. xml syntax used in php version 4

XML=load(XMLLocalFileName);
replaced by,
$XML=domxml_open_file($XMLLocalFileName);

documentElement
replaced by,
document_element()

SectionNode=RootNode->childNnodes(0);
replaced by,
$childnodes=$RootNode->child_nodes();
$SectionNode=$childnodes[1];


SectionNode->getAttribute("name");
replaced by,
$SectionNode->get_attribute("name");

DescriptionText =(DescriptionNode.text)
replaced by,
$DescriptionText =($DescriptionNode->get_content())

2. asp syntax and php syntax



1. dim DescriptionText
replaced by,
$ DescriptionText;

2. CStr(Request("section"))
replaced by,
$_GET["section"]

3. if isnull(SectionID) or trim(SectionID) = "" then

//body
end if
replaced by,
if($SectionID=="Null" || trim($SectionID)== "")
{
//body
}

4. XMLFileName = BaseXMLPath & "about/" & SectionID & ".xml"
Replaced by,
$XMLFileName = $BaseXMLPath."about/".$SectionID.".xml";

5. XMLLocalFileName = Server.MapPath(XMLFileName)
In asp Server.MapPath() function returns the physical location of the file name of asp file.
It return something like this c:/apache/htdocs/foldername/filename.asp
We can use below workaround to get file location.

$root=$_SERVER['DOCUMENT_ROOT'];
$folder_file=$_SERVER['PHP_SELF'];
$filename=basename($_SERVER['PHP_SELF']);
$filepos=strpos($folder_file,$filename);
$folder=substr($folder_file,0,$filepos);
$file_location=$root.$folder;
$XMLLocalFileName=$file_location.$XMLFileName;
Now the ‘$XMLLocalFileName’ return c:/apache/htdocs/foldername/filename.php
Anyway, if you know alternate simple solution you can share it here.

6. In asp the logical operators used in conditions like this
&&-‘and’ ||- ‘or’

But in php it is replaced by && and ||

7. In asp the array declaration is like this

Array()
But in php it is replaced by array()

8. The asp Request.ServerVariables("URL") function return folder name and filename.
In php its equivalent function is $_SERVER['PHP_SELF'];

9. In asp the function format is

function functionName(argument)
//body of function
end function
but in php function format is
function fuctionName(argument)
{
//body of function
}
10. In asp the for loop format is

for i=0 to sectionNode.length
//body of for loop
next
but in php its equivalent is,

for($i=0;$i<=count($sectionNode);$i++)
{
//body of for loop
}

11. In asp Response.Write() function is used to display content in webpage and Response.End() is used to end the execution flow.

Its equivalent function used in php is echo and die.

12. In asp Request.ServerVariables("HTTP_HOST") return the server name

Its equivalent function used in php is $_SERVER['HTTP_HOST']

13. the Request.Form() and Request.QueryString in asp is same as $GET[‘’] and $_POST[‘’] in php

14. the instr() function return the integer value of find string in asp, its equivalent function used in php is strpos()

15. the Int() function in asp is replaced by intval() in php.

16.the Rnd() function in asp is replaced by rand() in php

17. the Len() function in asp is replaced by strlen() in php

18.The Mid() function in asp returns a specified number of characters from a string, we used substr() function to return the same string in php.

19. the Replace() function in asp is replaced by str_replace() in php .

20. the Trim() function in asp is replaced by trim() in php.

More Articles...

No comments:

Search This Blog