PHP is a server side language. In simple words, client side language is one which is compiled by browsers (chrome, mozilla, etc) whereas the the server side languages are compiled by web servers(apache, IIS etc), the browsers only show the output.
Now what are the web servers?. the web servers are the software to serve the requests. so they listen to the requests 24 by 7. They listen to the requests on specific ports. these ports can be considered like there ears. by default they listen at port, 80. if port 80 is not available, then other port can b used. if the server uses, port 80 then no need to mention the port in URL otherwise, we have to mention the port while accessing the web page. Here are the some important points to be remembered.
- The php file is saved with extension .php
- The .html file should not contain php code as it can not compile it.
- The php file is placed in specific folder of the web server, for xampp it may be htdocs. it would not be compiled if it is placed outside that folder.
- To run the php page, it must be accessed using the proper URL of format IP:port/page.php. like if php page is placed on local machine and accessed from local machine, we would write url as http://localhost:port/page.php.
- In above video it has been demonstrated how to write and run php code.
let’s understand a simple code snippet written in php.
<title> hello php</title>
$x = 15;
$y = 30;
$z = $x + $y;
echo "sum is = " . $z;
echo "<br><h1> my heading </h1> </br>";
echo "Hello Php" ;
Line 6: <?php indicates the starting of the php code block. whenever we have to write php code, it should be enclosed in such block., we can have as many blocks as we want in single php page.
Line 7: php is loosely typed language. we do not need to declare a variable like int, float etc. Moreover, dollar sign is appended, before every variable. The variables are alphanumeric but they should not start with numerics. they can start with alphabets, or under score. The variables are case sensitive, although php itself is not case sensitive.
Line 9: all mathematical expressions are evaluated like Java or C language.
Line 10: dot . is used to concatenate two strings.
Line 13: ?> shows the end of php block.
Another handy function is var_dump(). it takes any variable as its argument and prints, not only contents but also type and size etc of the variable. it is very useful for debugging.