After installing WAMP server in our machine, to execute our PHP Programs we have to check whether our browser supports or not. To check whether our browser supports our wamp server, Do the following steps
1) Start ->WAMP Server
2) While installing WAMP Server by Default it is stored in location C:/xampp.Now go to that folder, make a click on xampp folder
C:/xampp -> htdocs -> create any folder name of your choice, here I have created sample folder to store our PHP Program
Now Inside sample folder, I have created one simple sample program in Notepad++,The following is simple code in php which will print Welcome to readexpert.com in browser, save the file with the extension hello.php
echo "<h2>Welcome to readeexpert.com</h2>";
Now, In our browser type
localhost/sample(The name of the folder we created in htdocs)
Now To run our first php Program, Make a click on hello.php, we will get the following output
Every php page must have the following
1) The correct filename extension ,usually php
2) PHP tags surrounding each block of PHP Code (the closing PHP Tag is optional if the file contain only PHP Code)
3) Conditional statement to make decisions
4) Loops to perform repetitive task
5) Functions or objects to perform preset task.
6) Arrrays to hold multiple values.
TELLING THE SERVER TO PROCESS PHP
PHP is a server-side language . The web server—usually Apache—processes your PHP code and sends only the results, usually as HTML, to the browser. Because all the action is on the server, you need to tell it that your pages contain PHP code.
This involves two simple steps:
Step1 : Give every page a PHP filename extension; the default is .php.
Use a different extension only if you are specifically told to do so by your hosting company.
Step 2: Identify all PHP code with PHP tags.
The opening tag is <?php and the closing tag is ?>. If you put the tags on the same line as surrounding code, there doesn’t need to be a space before the opening tag or after the closing one, but there must be a space after the php in
the opening tag like this:
<p>This is HTML with embedded PHP<?php //some PHP code ?>.</p>
HOW PHP SCRIPT WORK
The most important thing to understand is the difference between HTML and PHP.
In HTML , we write our code, upload it , and the users will subsequently download that page along with all the code .
HTML is sort of what we see is what we get.
With PHP it works a bit differently because we don’t actually download the code the author wrote .
What happens is that if we want to download a PHP page the code in that file is first processed by the server and we download the output of the code.
With the PHP the goal is to use the processing powers of the server to build dynamic web pages . For eg: if we write a script with the directions to show “Good morning” if it is before 10 am but after 5 am, and “good Afternoon” if
it is after 10 am but before 6 pm and “good night” after 6 pm before 5 am. These are all get processed before we download it, and we only get the result of the process , ” good night” for eg if it is 9pm.
A PHP script is executed on the server, and the plain HTML result is sent back to the browser.
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>:
<?php // PHP code goes here ?>
Incorporating PHP Within HTML:
PHP Program is responsible for passing back a clean file suitable for display in a web browser.
To trigger the PHP commands, we need to learn a new tag. Here is the first part:
The first thing we may notice is that the tag has not been closed. This is because entire sections of PHP can be placed inside this tag, and they finish only when the closing part is encountered, which looks like this:
A small PHP Hello World Program will be as follows
Echo ‘hello world”;
COMMENTS IN PHP:
There are two way to use comment in PHP,
SINGLE LINE COMMENT:
The single line comment is preceded by pair of forward slashes as shown below
//This is comment
We can use /* and */pairs of characters to open and cloase comments almost anywhere we like inside our code.