Articles by "PHP"
Showing posts with label PHP. Show all posts
Progrramers is optimized for Web Development Tutorials, Framework7, MeanStack, MongoDB, ExpressJS, AngularJS, NodeJS, HTML, CSS, JavaScript, PHP, SQL

PHP Whitespace Insensitive

In this chapter we will study about PHP whitespace Insensitive and Case Sensitive but before we go ahead first of all we should know that what whitespace is?

Whitespace is a character which is ‘Typed’ but it remains invisible on the screen. Typically it includes space, tabs, line changes etc.

PHP is whitespace insensitive language that ignores whitespaces. This means many whitespace characters are same to one whitespace character. Check out below example the try on your text editor.

Example - 1


<?php
 $x = 'https://www.progrramers.       com   '; //Whitespace is invisible on web page
 
 $y = 'https://www.progrramers. com';   //both will produce same result
 
  echo '<a href = "https://www.progrramers.com">' .$x. '</a> <br />';
  
  echo '<a href = "https://www.progrramers.com">' .$y. '</a> <br />';
 ?>


PHP Case sensitive

If you ever heard that PHP is case sensitive than it is true PHP is case sensitive language but there is one condition here. In PHP, all keywords like if, else, while, echo, etc., classes, functions, and user-defined functions are NOT case-sensitive. You can see yourself in below example

Example - 2


<?php
 $CAR = 'Skoda';
 
  echo $CAR;
  
  echo $car;
  
  echo $Car;
 ?>


All the variables in PHP are case sensitive. In above example you can see that $Car, $car and $CAR are not similar.  We will study about variables in next chapter.

PHP Tutorials - Whitespace Insensitive and Case sensitive

Progrramers is optimized for Web Development Tutorials, Framework7, MeanStack, MongoDB, ExpressJS, AngularJS, NodeJS, HTML, CSS, JavaScript, PHP, SQL

What is PHP document?


PHP document is a text file like HTML file which contains PHP scripts and it is stored on the server. In other words PHP documents that contains PHP scripts that executed on server and the result is parsed by HTML to display on web browsers.

Example - 1


<!DOCTYPE html>
<html>
<head> 
</head>
<body>
 <?php
 $x = 'https://www.progrramers.com';
 $y = 'PHP Tutorials';
 echo '<a href = '; ?> <?php echo $x . '>';?> <?php echo $y.'</a>';?>
</body>
</html>


Paste above code into your text editor, save as “anyname.php” and try to run the php script over http localhost it will show a link “PHP Tutorials”. Right click on browser’s blank area than click on view page source. You will find only HTML code not PHP script. It means that PHP script executed on the server and HTML display the results.

Example - 2


<!DOCTYPE html>
<html>
<head> 
</head>
<body>
 <?php
 $x = 'https://www.progrramers.com';
 echo '<a href = "https://www.progrramers.com">' .$x. '</a>';
 ?>
</body>
</html>


Same thing can be scripted in other way in above example but the result is same. It might be enough to make you understand that How php works actually. Let’s move forward

PHP file Extension


Like it is mentioned above PHP documents are save with “.php” extension. Although the php scripts are written along with HTML, CSS or JS codes, to execute the php script you must save the documents with “.php” extension. It doesn’t affects HTML, CSS or JS code execution.

Example - 3


<!DOCTYPE html>
<html lang = "en-US">
<head>
 <style>
  .php-main{
   background:#333333;
   color:#CCCCCC;
   margin: 10%;
   padding: 10%;
   text-align:center;
   border-radius: 15px;
   box-shadow: 5px 5px 5px;
   display:none;
  }
  .php-ver{
   text-shadow:2px 2px 2px black;
  }
 </style>
 <script>
  function showPhp(){
   var txt = document.getElementsByClassName('php-main');
   var btn = document.getElementsByClassName('btn');
    txt[0].style.display = 'block';
    btn[0].style.display = 'none';
   
  }
 </script>
</head>
<body>
<div style = "background:#333333; color:#CCCCCC; margin: 2%; padding: 2%; text-align:center;border-radius: 15px;">
 <h1>PHP Tutorials</h1>
</div>
<div class = "php-main" id = "php-main">
 <?php
  echo '<h2>Current Version of PHP is <br>'.'<span class = "php-ver">'.phpversion().'</span>'.'</h2>';
 ?> 
</div> 
<button class = "btn" onclick = "showPhp()">Show PHP Version</button><br /><br />
</body>
</html>


Basic PHP Syntax


PHP scripts are written inside php tags “<?php ?>”. PHP tags placed anywhere on the php document. If you are writing php script in the standard html document then php scripts can be written before <!DOCTYPE html> declaration.

Tips: To create Session and Cookies php scripts can be written top of the HTML codes before doctype declaration. We will study about Session and Cookies later chapters.

Example - 4


<?php  

//Statement goes here...

?>


PHP Expressions and Statements


Inside the php tags expressions and Statements are defined. A statement in PHP is any expression that is followed by a semicolon (;). In above examples you can see that each expressions that forms the Statement is ended with semicolon (;). See below example also

Example - 5


<?php 

$x = "Hello World";

echo $x;
?>


PHP Comments


If you have been through “HTML5 Tutorial - HTML Comments” you are already aware about the comments that is used while developing a web site. A comment is the portion of a program that exists only for the human reader and stripped out before displaying the programs result. There are two commenting formats in PHP

1. Single Line Comments
2. Multi Line Comments

Below are the examples of both single line and Multi line comments

Example - 6


<?php
// This is an example of Single Line Comment.

# This is an another example of Single Line Comment

/*
This is an example of Multi Line Comment
This is Second Line.
This is Third Line.
*/

$x = "Hello World";

echo $x;
?>


In next chapter we will study PHP Case sensitive and Whitespace Insensitive

PHP Tutorials - PHP Syntax and Extension

Progrramers is optimized for Web Development Tutorials, Framework7, MeanStack, MongoDB, ExpressJS, AngularJS, NodeJS, HTML, CSS, JavaScript, PHP, SQL

How to create PHP environment


Before we move ahead we remember you one thing that is in previous chapter it was mentioned that learning PHP is no more expensive. It is open source server side scripting language and available at no coast.

Warning! Please do not install without any assistant if you are not familiar with PHP installation and configuration. Please read this chapter completely at the end we put the best solution for you.

There are three main areas where you can use PHP

1. Websites and web applications (server-side scripting)
2. Command line scripting
3. Desktop (GUI) applications

For now we will go through Websites and web applications (server-side scripting). PHP is most flexible scripting language ever built which support all servers these days like IIS Apache etc. Like mentioned in previous chapter it runs on various platforms like Windows, Linux, Unix, Mac OS X, etc.

PHP Configuration and Installation


With below mentioned step you can set up PHP on your PC

1. Install a web server like Apache
2. Install PHP like version 5.5 or 5.6 (Latest 7.0)
3. Install a Database like MySQL.

PHP different version requires different version Visual C Runtime. Before we install please look at the below table

PHP Version Visual C Run Time Version Download Link
PHP 5.5 C Run Time Ver. 11 https://www.microsoft.com/en-us/download/details.aspx?id=30679
PHP 5.6 C Run Time Ver. 11 https://www.microsoft.com/en-us/download/details.aspx?id=30679
PHP 7.0 C Run Time Ver. 14 https://www.microsoft.com/en-us/download/details.aspx?id=48145

Below are link where you can download the above there software.

Program Version Download Link
PHP for Windows 5.6 to 7.2 http://windows.php.net/download#php-7.2
Apache Web server  2.4.29 http://httpd.apache.org/download.cgi
MySQL 5.7.20 https://dev.mysql.com/downloads/




Best Alternatives


Above software might lead you to do something wrong on your PC and the web server settings can produce some upsetting result. For best alternative here we can go through the web hosting or PHP ready package which can be easily set up and executed.

Web hosting


Signing up a PHP web hosting is great choice. Most popular companies like godaddy, bluehost, hostgator are providing the web host with domains where you can code and publish online and your work can be seen whole world 24X7. But this is little expensive.

Local hosting with XAMPP


XAMPP is very powerful ready to use package for PHP developers. In simple step you can download, install and activate the server and database with couple of click and you can start scripting. You can download XAMPP by click on the link https://www.apachefriends.org/index.html

PHP Tutorials - Create PHP Environment (Basics)

Progrramers is optimized for Web Development Tutorials, Framework7, MeanStack, MongoDB, ExpressJS, AngularJS, NodeJS, HTML, CSS, JavaScript, PHP, SQL

What is PHP?


PHP is a server side scripting language and a powerful tool to navigate with server database. PHP stands for Hyper Text Pre Processor. PHP provides the platform to build dynamic and interactive websites.

Why PHP?


PHP is an open source language that means it is free. It is free but it is best alternative to competitors like Microsoft ASP. It is widely used language program. Facebook is built over PHP. World’s most blogger use Wordpress which is an online, open source website creation tool written in PHP.

Benefits of Learning PHP


PHP is easy to learn. Learning other server side script like ‘ASP.Net’ might be little expensive but PHP requires only a PC and all the software to create environment for PHP scripting is free. PHP can run on various platforms like Windows, MAC OS X, Linux, Unix etc. and compatible with the all servers like Apache, IIS etc.

PHP supports wide range of database and can create dynamic web page contact. PHP can collect and perform the input Form data. PHP provide simplest way to execute database operations with MySQL and MySQL-i.

PHP is very easy to learn. You can easily set up the server on your Mac or windows PC and start the practice. Just copy and paste the example codes on your text editor and run the result over http localhost.

What should we know before start leaning PHP?


Before we start to learn PHP we must know below three languages:

  1. HTML
  2. CSS
  3. Java Script

Below is an example where HTML, CSS, JS and PHP are used all together.

Example - 1


<!DOCTYPE html>
<html lang = "en-US">
<head>
 <style>
  .php-main{
   background:#333333;
   color:#CCCCCC;
   margin: 10%;
   padding: 10%;
   text-align:center;
   border-radius: 15px;
   box-shadow: 5px 5px 5px;
   display:none;
  }
  .php-ver{
   text-shadow:2px 2px 2px black;
  }
 </style>
 <script>
  function showPhp(){
   var txt = document.getElementsByClassName('php-main');
   var btn = document.getElementsByClassName('btn');
    txt[0].style.display = 'block';
    btn[0].style.display = 'none';
   
  }
 </script>
</head>
<body>
<div style = "background:#333333; color:#CCCCCC; margin: 2%;
 padding: 2%; text-align:center;border-radius: 15px;">
 <h1>PHP Tutorials</h1>
</div>
<div class = "php-main" id = "php-main">
 <?php
  echo '<h2>Current Version of PHP is <br>'.'<span class = "php-
ver">'.phpversion().'</span>'.'</h2>';
 ?> 
</div> 
<button class = "btn" onclick = "showPhp()">Show PHP Version</button> 
</body>
</html>




What is a PHP file?


PHP file is a document that can contains text, HTML, CSS, Java Scripts, SQL along with PHP codes. PHP documents are saved with ‘.php’ extension. PHP files are stored and executed on the server that is why it is called server side scripting language.

What PHP can perform?


  1. PHP can generate dynamic page content
  2. PHP can create, open, read, write, delete, and close files on the server
  3. PHP can collect form data
  4. PHP can send and receive cookies
  5. PHP can add, delete, modify data in your database
  6. PHP can be used to control user-access
  7. PHP can encrypt data
  8. PHP can output HTML, XML and XHTML, Images, text, PDF and other several types of small and large files.
PHP is free and can be downloaded from its official website www.php.net.


PHP Tutorials - Introduction of PHP