Introduction
This blog will start discussing the basics of PHP (Hypertext Pre-Processor), a free, server side scripting language that is combined with HTML. Although targeted towards Web is has its concepts and ideas similar to that of JAVA and C++, and is now one of the most popular scripting languages today.
The main reasons why PHP is so popular amongst web developers apart from the fact that it’s free is because of its high performance, its ease of learning and its comprehensive set of database access functions.
Task
In this week's exercise we were asked to:
- Verify that PHP is working on our web server using our browser.
- Create an associative array of usernames and passwords and list the entire array in a table.
- Explain in our blog the difference between the echo() and print() functions.
Verify that PHP is working on our web server using our browser.
With the XAMPP package downloaded last week, checking if PHP is working is easy. In the XAMPP homepage (http://localhost) in the menu status, XAMPP shows the status of all its services and one of them is PHP. This service needs to be activated in order for PHP to work on the web server. Also further proof of the PHP service is running is the address being used in the web browser which is http://localhost/xampp/index.php. Since the webpage is working using a .php file then the PHP service is working.
Create an associative array of usernames and passwords and list the entire array in a table.
To script with PHP first you must create the "<?php" and "?>" open and close tags within the HTML file. Then I created an associative array “$logins” which lists all the user names and passwords. Then to list all the items in the array in a table, I first echoed the table border that will be used and then I used a while loop to echo each username and password.
Difference between Echo and Print Functions
After some research lead me to websites such as http://www.learnphponline.com/php-basics/php-echo-vs-print the following differences could be said about both language constructs.
Even though both are used for the same operation, Echo is considered to be faster (although no considerable speed differences will be noticed during runtime) than "print" because it simply spits out HTML mark-up in its calling position within the document without returning a value unlike “print”. Print - Returns an integer value 1 for no reason.
Also "Echo" can take more than 1 parameter when used without a parentheses by using commas (","), "print" cannot have multiple expressions.
As you can see above the differences between both functions are small, the one to choose depends on ones’ likes. Choosing "echo" should be better because of performance and multiple parameters but print will always retain its nostalgia factor.
No comments:
Post a Comment