After the Hello Phalanger program, lets lOOK at something more interesting. What if one can write assemblies (or class libraries) in PHP which in turn can be used in .Net applications (Web or Desktop)? This will prove useful if you have an existing investment done in a complicated logic written in PHP and now want to use the same logic in a .Net application.
As a simple example, we write a PHP class library named Cry to which has a function/method called GetMD50. This function simply accepts a string, uses PHP's inbuilt MD5 function and returns the MD 5 hash of the string. In Visual Studio, click on File> New Project. Under the "Project Types" menu, select Phalanger. From the right pane, select Phalanger Class Library. For the project name, type in Crypto and then click on Ok button. Now go to the the Solutions Explorer and here click on the Library.php, which will look like this:
You need to modify the code to the following: Now build the project and create a
new .Net Web application in Ct. Right click on the Project and click on Add Reference. Then browse to the assembly file (Crypto.dll) of Crypto. The assembly file can be found, typically, in My DocumentsWisual Studio 200S\Projects\Crypto\Crypto\bin\Debug. You will also need to add a reference to Php¬NetCore.dll (found in Program Files\Phalanger\Bin director}).
Now in the code behind (Default.aspx.cs, for example), you can call the the GetMD50function, of the assembly written in PHP. This can be done as shown below: To explore more about Phalanger plug-in, browse to the site and learn more about other nifty uses that you can put this software for.




Reply With Quote
Bookmarks