What is PHP
PHP (recursive acronym
for PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose
scripting language. PHP is geared towards web development. It was originally
created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in
1995. PHP is the most popular open-source server-side scripting language that
many developers (devs) use for web development.
PHP code are executed by
a part of PHP called the PHP run time. The PHP run time looks for two different
things within a web browser before it can identify that the code written are
PHP code. They are the file extension: for the PHP run time to know that the
webpage will contain a PHP code, save the file name with a .php extension.
Secondly, the code MUST be writing within the PHP code block. It is
important to note that PHP help us to develop a dynamic website.
How to Write PHP Code
Explanation on Source Code
Every PHP code is written
within the PHP tag which is also called the PHP code block (<?php ?>). Writing a PHP code
outside the PHP code block will not lead to an error but the web browser will
interpret the code as a normal text and render
it as u write it on the web browser. Echo is an output function outputting the
string Welcome to EasyCode blog. A string can be written either
within a single quote or a double quote but don’t mix it up (Our example uses a single quote). Always end a PHP
code with a semi colon to avoid syntax error. The semi colon indicate the end of line and not doing
so will lead to a syntax error at run time.
How to Display our Output on Web-browser
Output of The Code Above
Inspecting PHP Source Code Via Web Browser
Developers and users can view source code from the developer console. The developers console provide a means for accessing all of the information that has been sent to your machine - from fragments to files. The developers console is largely meant to be used as a tool for developers - primarily for debugging their source code. You can access the console by following the steps below.
Open your web browser, right click and select inspect code, what will be displaying will be just the code and not all your source code. This is because PHP is a server side programming language.
PHP and White Space
White space means nothing
to PHP, the white space will not be rendered on the web browser or when you are
inspecting your code, but it is often use because it help format your code and gives
it a better look.