PHP BASICS


Lesson 1. Syntax of a Webpage

Basic Facts

- PHP means Hypertext Preprocessor

- PHP code can be anywhere in the document but preferably at the top before the "DOCTYPE" element

- PHP script starts with (< ? php) and ends with (? >)

- The default file extension for PHP files is ".php"

- (// and # ) within the php tag refers to a single line comment

- (/* */) refers to multiple line comments

- All user defined functions, classes and keywords (e.g. if, else, while, echo etc.) are not case sensitive

& lt; & gt; surrounding a text will add tags to the text

< pre>< code>, < /code>< /pre> surrounding a code will render it readable and not executable

- (!DOCTYPE html) attribute is an instruction to the web browser about what version of HTML the page is written in

- (html lang="en") attribute canbe used to declare the language of a web page

- (meta charset="UTF-8") attribute specifies the character coding for the HTML document and can be locally overridden with the "lang" attribute

PHP Elements (Visit php.net for list of elements and sample codes)

- < hr> for horizontal rule

PHP Built in display functions (visit php.net for a list of functions)

- print and echo functions are both for displaying information on the page. They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print .

** print

< ?php print('Hello World!'); ?>

** echo

< ?php echo "My Name is chabek"; ?>

===================================================
Format of a webpage

< ! DOCTYPE html>

< html lang = " en " >

     < head >

          < meta charset = " UTF-8 " >

          < title > < / title >

          Link to External CSS files / Plugins

          < link href="../assets/styles.css" rel="stylesheet">

          < link rel = "stylesheet" href = "src / css / bootstrap. css">

          Link to Javascript Plugins

          < script src = "src / jquery - 3.2.0.min. js">

          Internal CSS for HTML div's created within the body tag

          < s tyle >

                **map within 100% of view point/entire page

                #mapdiv {

                height:100vh;

                 padding: 3px;

                }

           < / s tyle>

     < / head >

     < body >

          HTML div tags

          < d iv class="wrapper">

             < a h ref="/" title="Back to directory" id="logo">

             < i mg src="../assets/img/banner_tutor.png" alt="PHP">

     < /body >