Punjabi revolution tutorials PHP introduction

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.

  1. The php file is saved with extension .php
  2. The php file can contain html, css and javascript.
  3. The .html file should not contain php code as it can not compile it.
  4. 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.
  5. 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.
  6. In above video it has been demonstrated how to write and run php code.

let’s understand a simple code snippet written in php.

As I mentioned, we can write html, css and javascript code in php file, the code contains html tags. lets analyze the code line by line.

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 10: echo is used to display on the screen, you can take it as alternative to Javascript document.write.

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.


Leave a Reply

Your email address will not be published. Required fields are marked *