WELCOME TO THE WORLD OF PHP the ultimate (Hypertext Preprocessor) Overview Definition History Uses Advantages/Disadvantages Advantages of PHP over ASP Differences between PHP and Cold-fusion Difference between JSP and PHP Basic Syntax Complex Syntax Similarities between ASP and PHP Definition Programming Language Server-side scripting language Html Embedded Scripting Language primary purpose of which to generate HTML It focuses on the logic of how a page responds to user input, not how the page looks History PHP is a language for creating interactive web sites over 3.3 million web sites around the world. Originally name: "Personal Home Page Tools" when it was created in 1994 by Rasmus Lerdorf to keep track of who was looking at his online resume Uses of PHP Helps in reading and writing files Can do basic file and directory maintenance Take content, use in generation of files in various formats i.e. HTML and PDF Manages graphic content Read, write info in database. Advantages of PHP and Disadvantages Cost –free Cross-platform compatibility (Windows, Macintosh, or a version of Unix, ): Compiled and built on 25 platforms Error handling is not as sophisticated as ASP Advantages of PHP over ASP PHP runs faster than ASP PHP is Free . PHP is more efficient with memory PHP can be run on any system with no performance issues PHP is tightly integrated with MySQL ASP commonly uses Microsoft Access which is much slower than MySQL More object oriented than ASP Database connections in PHP > 200% (higher) Differences between PHP and ColdFusion Cold-Fusion: Web application development tool that allows developers to build dynamic data-driven applications for use on the Internet and intranets Cold Fusion (Platform) Relatively limited platform selection. ieWindows, Solaris, Linux or HP/UX. (Language) Really fast and easy for display pages and database interaction (Database Support):Abstracts database connections, making them simple to use, Not as easy for the easy stuff, but much easier for the hard stuff. Has extremely strong native DB support (File System Support):Adequate file support, but is quirky and not feature-rich Comprehensive file system support (Error-handling):good try/catch functionality, making formal error handling possible has no formal error handling PHP If compiled, runs Basic/General Syntax <?php ... ?> <html> <head> <title>My first PHP page</title> </head> <body> This is normal HTML code <?php // PHP code goes here ?> Back into normal HTML </body> </html> Variables in PHP loosely “typed language” i.e given variable can be an integer, floating-point number, string, object, or an array Integer: mathematical data type and represents any whole number and usually can be any value from a negative value to a positive value. floating-point number represents any value that contains a decimal point. EXAMPLE OF AN INTEGER VARIABLE <?php // Both of the following are equivalent to 1.234 $myfloat = 1.234; // Standard decimal notation EXAMPLE OF AN INTEGER VARIABLE $myfloat = .001234e3; // Scientific notation <?php ?> // All of the following are numerically equivalent $myint = 83;// Normal decimal notation $myint = O123; // Octal notation for the # 83 $myint = 0x53; // Hexadecimal notation for # 83 ?> Condition-code in PHP <html> <? $var = date("H"); if ($var <= 11) { echo "good morning"; } else { if ($var > 11 and $var < 18) { echo "good afternoon"; } else { echo "good evening"; } } ?> </html> Functions in PHP code SAMPLE CODE <? function show_form($value="") { ?> <form action="submit.php3" method="post"> <input type=text name=value value="<?echo $value?>"> <input type=submit> </form> <? } PHP EMAIL Built-in function called mail(), that helps sends email. mail($receiver, $subject, $message, "From: $sender"); NOTE: The mail() function -return a variable -true or false, with regard to whether the mail was sent - echo information to your user, as to the email status. $sent = mail($receiver, $subject, $message, "From: $sender"); if ($sent) { echo "your message was sent"; }else { echo "your message was not sent"; } ASP EMAIL CODE(An idea with respect to ASP) <% Dim MyBody Dim MyCDONTSMail %> <% Set MyCDONTSMail = CreateObject("CDONTS.NewMail") MyCDONTSMail.From= "somebody@nowhere.com" MyCDONTSMail.To= "nobody@nowhere.com" MyCDONTSMail.Subject="This is a Test" MyBody = "Thank you for ordering that stuff" & vbCrLf MyBody = MyBody & "We appretiate your business" & vbCrLf MyBody = MyBody & "Your stuff will arrive within 7 business days" MyCDONTSMail.Body= MyBody MyCDONTSMail.Send set MyCDONTSMail=nothing %> Similaritites betweeen ASP and PHP Similarities between PHP and ASP Positive Aspect Easy to develop. Easy database connection/configuration. The presentation is separate from processing. Negative Aspects They are scripting languages that has a narrow scope. They are scalability. Differences between JSP and PHP JSP PHP JSP uses Java as its scripting language defines its own scripting language, which looks and feels a lot like Perl. Uses VBScript JSP is much more powerful, since it has access to all the Java libraries Object-Oriented, so leads to cleaner code that's easier to debug, maintain, and improve. access to PHP libraries Also allows objects, but the object model is more primitive, and most scripted pages ignore PHP objects and just use normal variables.