A CSS rule set contains a selector and a declaration block.
Selector: Selector indicates the HTML element you want to style. It could be any tag like <h1>, <title> etc.
Declaration Block: The declaration block can contain one or more declarations separated by a semicolon. For the above example, there are two declarations:
color: yellow;
font-size: 11 px;
Each declaration contains a property name and value, separated by a colon.
Property: A Property is a type of attribute of HTML element. It could be color, border etc.
Value: Values are assigned to CSS properties. In the above example, value “yellow” is assigned to color property.
$to: specifies receiver or receivers of the mail. The receiver must be specified one of the following forms.
user@example.com
user@example.com, anotheruser@example.com
User <user@example.com>
User <user@example.com>, Another User <anotheruser@example.com>
$subject: represents subject of the mail.
$message: represents message of the mail to be sent.
Note: Each line of the message should be separated with a CRLF ( \r\n ) and lines should not be larger than 70 characters.
$additional_headers (optional): specifies the additional headers such as From, CC, BCC etc. Extra additional headers should also be separated with CRLF ( \r\n ).
PHP Mail Example
<?php
ini_set("sendmail_from", "sonoojaiswal@javatpoint.com");
$to = "sonoojaiswal1987@gmail.com";//change receiver address
$subject = "This is subject";
$message = "This is simple text message.";
$header = "From:sonoojaiswal@javatpoint.com \r\n";
$result = mail ($to,$subject,$message,$header);
if( $result == true ){
echo "Message sent successfully...";
}else{
echo "Sorry, unable to send mail...";
}
?>
If you run this code on the live server, it will send an email to the specified receiver.
PHP Mail: Send HTML Message
To send HTML message, you need to mention Content-type text/html in the message header.
<?php
$to = "abc@example.com";//change receiver address
$subject = "This is subject";
$message = "<h1>This is HTML heading</h1>";
$header = "From:xyz@example.com \r\n";
$header .= "MIME-Version: 1.0 \r\n";
$header .= "Content-type: text/html;charset=UTF-8 \r\n";
$result = mail ($to,$subject,$message,$header);
if( $result == true ){
echo "Message sent successfully...";
}else{
echo "Sorry, unable to send mail...";
}
?>
PHP Mail: Send Mail with Attachment
To send message with attachment, you need to mention many header information which is used in the example given below.
<?php
$to = "abc@example.com";
$subject = "This is subject";
$message = "This is a text message.";
# Open a file
$file = fopen("/tmp/test.txt", "r" );//change your file location
if( $file == false )
{
echo "Error in opening file";
exit();
}
# Read the file into a variable
$size = filesize("/tmp/test.txt");
$content = fread( $file, $size);
# encode the data for safe transit
# and insert \r\n after every 76 chars.
$encoded_content = chunk_split( base64_encode($content));
# Get a random 32 bit number using time() as seed.
$num = md5( time() );
# Define the main headers.
$header = "From:xyz@example.com\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; ";
$header .= "boundary=$num\r\n";
$header .= "--$num\r\n";
# Define the message section
$header .= "Content-Type: text/plain\r\n";
$header .= "Content-Transfer-Encoding:8bit\r\n\n";
$header .= "$message\r\n";
$header .= "--$num\r\n";
# Define the attachment section
$header .= "Content-Type: multipart/mixed; ";
$header .= "name=\"test.txt\"\r\n";
$header .= "Content-Transfer-Encoding:base64\r\n";
$header .= "Content-Disposition:attachment; ";
$header .= "filename=\"test.txt\"\r\n\n";
$header .= "$encoded_content\r\n";
$header .= "--$num--";
# Send email now
$result = mail ( $to, $subject, "", $header );
if( $result == true ){
echo "Message sent successfully...";
}else{
echo "Sorry, unable to send mail...";
}
?>
To get the current page URL, PHP provides a superglobal variable $_SERVER. The $_SERVER is a built-in variable of PHP, which is used to get the current page URL. It is a superglobal variable, means it is always available in all scope.
If we want the full URL of the page, then we’ll need to check the protocol (or scheme name), whether it is https or http. See the example below:
<?php
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
$url = "https://";
else
$url = "http://";
// Append the host(domain name, ip) to the URL.
$url.= $_SERVER['HTTP_HOST'];
// Append the requested resource location to the URL
$url.= $_SERVER['REQUEST_URI'];
echo $url;
?>
Output
Note: The isset() function is used here to check whether HTTPS is enabled or not. It checks whether a variable exists or not.
Or, we can also get the full URL of current page using another way given in the next example.
To create a newline, PHP provides nl2br() function. It is an in-built function of PHP, which is used to insert the HTML line breaks before all newlines in the string. Although, we can also use PHP newline character \n or \r\n inside the source code to create the newline, but these line breaks will not be visible on the browser. So, the nl2br() is useful here.
The nl2br() function contains these newline characters \n or \r\n which combinely create the newline. Apart from nl2br() function, a html break line tag </br> is used to break the string. The </br> tag should be enclosed in double quotes, e.g., “</br>”.
For Example
To create the newline in PHP, let’s see the number of examples.
Example 1
Let’s take an of example to create the newline with the help of nl2br() function.
<?php
echo nl2br(“New line will start from here\n in this string\r\n on the browser window”);
?>
Output
In this example, we can see that the nl2br() function has contained “\n” and “\r\n” characters in the string for newline. We can see the result of the following program in the below output.
New line will start from here
in this string
on the browser window
Example 2
<?php
echo "One line after\n another line";
echo " One line after\r\n another line";
?>
Output
In the above example, we can see that after “\n” or “\r\n” character, string did not start from the new line. “\n” and “\r\n” alone are not enough for creating a newline in the string, as the whole string is displayed in a single line.
One line after another line One line after another line
Note: The character “/n” is used in Linux to write a newline whereas in windows “\r\n” is used. For the safe side use the “\r\n” character for creating newline instead.
Example 3
<?php
echo "One line after\n another line";
echo "</br>";
echo "One line after\r\n another line";
?>
Output
Here, we break the lines using html break line tag “</br>“.
One line after another line
One line after another line
To count all the elements in an array, PHP offers count() and sizeof() functions. The count() and sizeof() both functions are used to count all elements in an array and return 0 for a variable that has been initialized with an empty array. These are the built-in functions of PHP. We can use either count() or sizeof() function to count the total number of elements present in an array.
For example
We will discuss the program implementation for all the array elements using both count() and sizeof() methods.
Example 1: Counting using count()
<?php
$ele = array("Ryan", "Ahana", "Ritvik", "Amaya");
$no_of_ele = count($ele);
echo "Number of elements present in the array: ".$no_of_ele;
?>
Output
Number of elements present in the array: 4
Example 2
<?php
$ele = array(14, 89, 26, 90, 36, 48, 67, 75);
$no_of_ele = sizeof($ele);
echo " Number of elements present in the array: ".$no_of_ele;
?>
Output
Number of elements present in the array: 8
Example 3: Counting using sizeof()
<?php
$ele = array("Jan", "Feb", "Mar", "Apr", "May", "Jun");
$no_of_ele = sizeof($ele);
echo " Number of elements present in the array: ".$no_of_ele;
?>
Output
Number of elements present in the array: 6
Example 4
<?php
$ele = array(14, 89, 26, 90, 36, 48, 67);
$no_of_ele = sizeof($ele);
echo " Number of elements present in the array: ".$no_of_ele;
?>
A PHP framework is a platform which allows a web developer to develop the web application. In simple words, it provides a structure to develop web application. These frameworks save lots of time, stop rewriting the repeated code and provide rapid application development (RAD). PHP frameworks help the developers to rapid development of application by providing the structure.
Following a list of top 10 PHP frameworks is given below:
Laravel Framework
CodeIgniter Framework
Symfony Framework
Zend Framework
CakePHP Framework
Phalcon Framework
Yii Framework
Slim Framework
FuelPHP Framework
PHPixie Framework
1. Laravel
Laravel is an open-source web application framework which released in June 2011. It is developed by Taylor Otwell. Laravel is very popular because it handles complex web applications more securely and faster than other frameworks. Laravel makes lots of common tasks of web projects much easier, such as authentication, session, routing, and caching, etc.
The main goal of Laravel is to make web development easy and best for the developers without sacrificing application functionality. It provides powerful tools which are necessary for large and robust application. An inversion of control container, tightly integrated unit testing support, and expression migration system provides the tools that help to build any application with which we are tasked.
Advantage of Laravel Framework
Laravel follows the MVC design pattern. It offers the following benefits that are given below:
Laravel makes web application scalable and more secure than other frameworks.
It includes interfaces and namespace, which helps to organize and manage resources.
Laravel reuse the components from the other frameworks in web application development that saves the time of developer to design the web application.
Website designed in Laravel is easy, secure, and protects from several web attacks.
It supports automation testing, which saves lots of time.
Laravel uses its own template engine called Blade and ORM called Eloquent.
Disadvantage of Laravel Framework
Legacy systems do not easily transfer to Laravel.
Some upgrades might be problematic in Laravel
Methods like reverse routing and caching are complex.
2. CodeIgniter
CodeIgniter is an application development framework with small footprints which makes it much faster than other frameworks. It was released on February 28, 2006, by EllisLab. It minimizes the size of code needed for a given task and provides easy solutions to the complex coding problems.
CodeIgniter is not totally based on the MVC framework. It is one of the oldest frameworks with faster and high performance. We can develop projects much faster than a scratch, as it provides a large set of libraries, simple interface, and logical structure to access these libraries. It can be easily installed, and it requires minimal user configuration.
Advantage of CodeIgniter Framework
CodeIgniter is an open-source and lightweight framework.
CodeIgniter is faster with database tasks than compared to other frameworks.
It is easy to install and well documented, so it is good for PHP beginners.
It offers built-in security tools.
CodeIgniter provides exceptional performance.
CodeIgniter offers some features that help to protect web application with security threats such as SQL injection, remote code execution, and cross-site scripting attack.
Disadvantage of CodeIgniter Framework
CodeIgniter does not support modular code separation. Hence, developers need to put extra effort and time to maintain the code.
It is the only PHP based but not object-oriented in some parts.
CodeIgniter has no built-in ORM.
It has fewer tools and built-in libraries than other frameworks.
3. Symfony
Symfony is another popular framework which was introduced on October 22, 2005, by Fabian Potencier. It is released under MIT license. It is a set of PHP components to create websites and web application. Symfony framework is a perfect choice among frameworks to develop large-scale enterprise projects.
Symfony is an open-source framework of PHP which is sponsored by SensioLabs. This framework is designed for developers who create a full-featured web application. Lots of open source projects like Drupal, Composer, and phpBB use Symfony components. Symfony integrates with PHP Unit and independent library. Symfony framework is flexible and handles enterprise application with billions of connections. It is used to build micro-sites.
Advantage of Symfony Framework
Symfony is a flexible and powerful framework.
As Symfony is an open-source framework, it allows us to develop without any constraint.
It prevents from web attacks and SQL injection.
Symfony framework provides code reusability and easy maintenance.
It maintains complete, clearly written, well-structured, and up-to-date documentation.
Disadvantage of Symfony Framework
Symfony framework needs more efforts to learn than other frameworks such as Laravel and Yii.
Security is a bit hard in the Symfony framework.
File parsing is difficult to handle in Symfony framework.
Performance and speed are the main drawbacks of it.
Large-scale applications are developed using Symfony rather than small-scale.
4. Zend Framework
Zend is an open-source, web application framework, which is developed on March 3, 2006. It is a collection of 60+ packages which is available on GitHub and can be installed via composer. Zend is pure object-oriented, which is developed on the basis of the MVC design pattern. Zend was developed in agile methodology that helps to deliver a high-quality application to the enterprise client.
IBM, Google Microsoft, and Adobe are the partners of Zend. There are many features comes with Zend Framework version 2 such as drag and drop editor with front-end technology support (HTML, JavaScript, CSS), cryptographic coding tool, PHP Unit testing tool, instant online debugging, and a connected database wizard.
Advantage of Zend Framework
Zend is highly customizable framework. Performance of Zend Framework version 3 is four times higher than its previous version.
We can easily test the framework because PHPUnit is integrated with Zend.
Zend has a large community base, and it is well-documented.
We can delete modules and components which has no use in the application.
We can use the components of our own choice.
It supports multiple databases, such as MySQL, PostgreSQL, Microsoft SQL, and Oracle.
Disadvantage of Zend Framework
Zend Framework is heavy and huge as it has a larger set of libraries, components, and classes.
Cost of plug-ins of Zend Framework is higher than other frameworks.
It has large documentation with minimal detail of the framework, hence documentation is hard to use as a guideline for the whole development of the project.
5. CakePHP
CakePHP is a web development framework of PHP which was released on April 2005, and it is licensed under the MIT License. It is based on MVC (Model View Controller) architecture and follows ORM techniques. CakePHP 3 is running on PHP 7.3 version. It has excellent speed, security, and reliability. CakePHP is an open-source framework, hence it is free to use.
CakePHP offers several features, such as SQL injection prevention, Cross-Site Request Forgery (CSRF) protection, Form tampering Validation, good documentation, and cross-scripting platform (XSS) prevention. It has a set of conventions which guide while developing the application. Due to CRUD (Create, Read, Update, and Delete) framework, it is one of the easiest frameworks to learn. It powers BMW, Express, and Hyundai websites.
Advantage of CakePHP
It follows ORM (Object Relational Mapping) techniques which help developers to create a good query and as well as code.
It provides plug-in support to keep the code clean and graceful.
CakePHP allows the developer to create reusable code, so it is not required to write new code all the time, thus it saves lots of time and effort.
Most of the developers prefer the CakePHP because of easy debugging and testing of any application.
CakePHP provides built-in security features and authentication that protect the application more than other frameworks.
Disadvantage of CakePHP
It is a slowest performing framework.
It is best for the small and medium project rather than large.
One-way routing in CakePHP is often a disadvantage compared to other frameworks like Rails and Ruby.
While using CakePHP, we have to update the default routes for creating effective URLs, which required more work than other frameworks.
Documentation is not good. It needs improvement.
6. Phalcon
Phalcon is a full-stack web framework which is written as a C-extension. It is released on November 14, 2012, and licensed under the BSD License. Phalcon framework is developed by Andres Gutierrez and his group of collaborators. Phalcon is a combination of C and PHP language, but developers do not need to learn C to use Phalcon.
It is an open-source framework which is based on MVC (Model View Controller) design pattern. Phalcon provides equal support to both relational and non-relational databases. It is the first framework that implements the ORM technique in C language. Phalcon is a loosely coupled framework.
Advantage of Phalcon
Installation of Phalcon framework is easy, and it is suitable for developing a highly configurable web application.
It provides several features, such as asset management, a universal auto-loader, translation, security, and caching.
Phalcon is well-documented and easy to learn.
Applications designed using Phalcon framework are highly secured.
Phalcon is a loosely coupled framework so as per application requirement the developer can build a project with a directory structure.
Disadvantage of Phalcon
It cannot run on shared hosting.
It is not as much as popular like other frameworks. Many developers are not aware with the Phalcon framework.
Developer should have knowledge of HTML, CSS, and JavaScript before starting development with the Phalcon framework.
7. Yii
Yii is a high performance, open-source framework of PHP for rapidly developing web applications. Yii is pronounced as Yee or [ji:], which means “Simple and Evolutionary” in Chinese. It also stands for Yes it is! Yii is a universal web programming framework because it is suitable for all kind of web application. It is built around Model-View-Controller.
Yii is a component-based PHP framework. It is suitable for large-scale application development such as forums, E-commerce projects, Content management system (CMS), and portals, etc., because of its component-based architecture and sophisticated caching support. Yii is a secure, fast, efficient, and pure object-oriented.
Yii version 2 comes with a set of AJAX-enabled features and also integrated with jQuery.
Advantage of Yii
It offers the maximum functionality by adding the minimum possible overhead.
Yii is very efficient as we can write simple and more code in less time.
Using Yii framework developer can easily create an application in a very short time.
This framework is highly secured and provides excellent support for third-party components.
Disadvantage of Yii
The developer needs to know the basics of OOP because Yii is a pure object-oriented programming framework.
There is less number of experts of Yii frameworks as compared to other frameworks.
Yii framework does not provide AR queries.
While developing applications, Yii seeks more attention from the developer.
8. Slim Framework
Slim is a micro framework of PHP that helps to develop simple and powerful web application and APIs quickly. It is developed and maintained by Josh Lockhart, Rob Allen, Andrew Smith, and their team. Slim’s creator was inspired by Sinatra micro framework of Ruby. It is a lightweight framework.
Slim, which is a micro framework, is suitable to create a CRUD application with PHP for small-scale rather than a full-stack framework. Slim is a perfect tool for rapid prototyping. We can create full-featured web applications with the user interface. As Slim is a dispatcher, it receives HTTP requests, invokes a callback routine, and returns an HTTP response.
Slim offers several features such as Client-side HTTP caching, URL routing, session, and cookie encryption, and flash messages.
Advantage of Slim Framework
Slim is easy to learn like PHPixie. It is used to develop RESTful APIs and web services.
It is an excellent framework for developing a small web application with great functionalities.
We get complete control of external tools because Slim supports dependency injection.
We can inspect and manipulate HTTP message method, URI, status, headers, body, and the cookie because Slim supports any PSR-7 HTTP message implementation.
Disadvantage of Slim Framework
It is required to learn the different version of Slim to work on them.
It just a configurable container, not dependency injection, i.e., dependency injection is too weak.
We need to have strong bases of patterns and extreme knowledge of libraries to convert it into a Slim dependency.
It is not beneficial for long-running projects.
9. FuelPHP
FuelPHP is an open-source PHP framework build with advanced functionalities. Dan Horrigan started the FuelPHP framework at the end of 2010, after that Phil Sturgeon, Harro Verton, Jelmer Schreuder, and Frank de Jonge joined the team immediately. Steve West joined the team in 2013, and after that in 2014, Mark Sagi-Kazar joined.
FuelPHP is a flexible, easy, and community-driven PHP web framework. It is an MVC (Model-View-Controller) framework which is extremely portable framework so it can work on almost any server. FuelPHP have full HMVC (Hierarchical Model-View-Controller) implementation.
Note: FuelPHP is supported by the above version of PHP 5.3.
Advantage of FuelPHP
FuelPHP offers a utility called “Oil” which is designed to help in fast development, increase efficiency, and also assist debugging and testing.
It supports CSRF prevention with tokens, Query Builder, and input filtering that assists us in preventing from SQL injection attack.
We can provide more functionality into packages that extend the FuelPHP core.
Using powerful PHPSecLib, it handles encryption, decryption, and hashing.
It offers full-featured RBAC authentication, which is based on ORM and secure hashing function for passwords including (PBKDF2).
Disadvantage of FuelPHP
The developer needs to learn each time when a new version releases because the documentation guides keep on changing.
The developers have to learn ahead for effective use of FuelPHP.
It is not friendly for beginners.
The developer’s community is not much active with FuelPHP as with other frameworks.
10. PHPixie
PHPixie is an open-source PHP framework which was introduced in 2012. It is easy to use and requires fewer configurations. The main goal of this framework is creating a high-performance framework for read-only websites. Like the FuelPHP framework, it also implements the HMVC (Hierarchical Model-View-Controller) design pattern.
PHPixie is built by using independent components which can be used with the framework itself. These components are 100% unit tested and require minimum dependency. It is a lightweight framework which supports MongoDB database. PHPixie offers some features such as input validation, ORM caching, authentication, and authorization capabilities.
Advantage of PHPixie
PHPixie is good for social networking websites, web application development services, and customized web applications.
It is built by using independent components so that we can use it without the framework itself.
Experienced in CodeIgniter or Kohana can easily understand and learn it.
It provides more adaptability, as everything is effortlessly expandable, over-ridable, and simple to learn.
PHPixie offers a full-stack framework that focuses on effectiveness.
Disadvantage of PHPixie
It is not as much as popular compared to other frameworks like Laravel, Symfony, Zend, etc.
PHP stands for Hypertext Preprocessor, which is an open source scripting language. It is a server-side scripting language and a powerful tool for creating a dynamic and interactive website.
PHP is an interpreted language, so it doesn’t need compilation. It is specially designed for server-side scripting, which executes on the server. PHP can be easily embedded with HTML files.
Note: PHP is mainly used to develop server-side applications.
It has several advantages that are given below:
We can execute a PHP code on different platform such as Windows, Linux, UNIX, Solaris, etc.
It is easy to use and learn.
PHP provides a built-in module which helps it to connect with the database easily.
PHP is an open source language that means it is available for free of cost.
In general, PHP is cheap, cross-platform, fast, and reliable to develop web applications.
What is Python?
Python is an interpreted, Object-oriented programming language, which is used for web development, software development, and system scripting, etc. It is a case-sensitive language. Python 3.7.2 is the latest version of Python.
Python is a general-purpose, high-level programming language. Program written in Python language does not need to be compiled in advance in order to run. There are many popular applications which have been developed in Python such as YouTube, Google, DropBox, Instagram, Quora, etc.
Python is not only a web language, because it is also used for developing console app, Mobile app, Desktop app, IOT applications, AI applications as well as for software testing and hacking, etc.
There are several advantages of Python that are given below.
Python is a dynamically typed language.
It has a very simple and straight forward syntax as its code is easy to write and debug.
Indentation is used in place of curly braces in Python.
It uses variables without the declaration.
We can solve the complex problem in very less time and with the minimal line of code using Python.
We can create Python applications for different platforms like Windows, Linux, UNIX, and Mac OS.
Difference between PHP and Python
Python and PHP both are free and open-source languages. The main difference between Python and PHP is that Python is a general-purpose programming language, whereas PHP is mainly used for web development.
PHP
Python
PHP is a specialized web development programming language.
PHP stands for Hypertext Preprocessor, which is an open source scripting language. It is a server-side scripting language and a powerful tool for creating a dynamic and interactive website.
PHP is an interpreted language, so it doesn’t need compilation. It is specially designed for server-side scripting, which executes on the server. PHP can be easily embedded with HTML files.
Note: PHP is mainly used to develop server-side applications.
It has several advantages that are given below:
We can execute PHP code on different platform such as Windows, Linux, UNIX, Solaris, etc.
It is easy to use and learn.
PHP provides a built-in module which helps it to connect with the database easily.
PHP is an open source language that means it is available for free of cost.
In general, PHP is cheap, cross-platform, fast, and reliable to develop web applications.
What is Node.js?
Node.js is a JavaScript programming language which runs on the server. It helps to create dynamic and interactive web pages. Node.js file is saved with .js extension, and it only contains JavaScript code. It executes JavaScript code outside the browser.
Node.js is an open-source language which executes in different environments such as Windows, Linux, UNIX, and Mac OS, etc.
Node.js has many advantages which are listed below.
Node.js is fast and lightweight.
It is more secure than PHP.
Node.js allows us to write JavaScript code for both client and server-side.
Node.js offers scalability, i.e., it easy to scale the application vertically as well as horizontally.
JavaScript is now available for every browser and as well as it can run on each server due to Node.js.
Difference between PHP and Node.js
PHP and Node.js both are server-side scripting languages; thus, they have become the competitor for each other. They are bound to have some similarities and also some differences. Following are some differences based on their functionality and features.
Features
PHP
Node.js
Runtime Environment
PHP is straightforward to install and use at server-side.
PHP is straightforward to install and use at server-side.
Powered by
PHP is powered by Zend engine.
Node.js is powered by Google’s v8 JavaScript engine.
Execution
PHP is synchronous except some APIs.
It is totally asynchronous.
Framework
PHP has many frameworks for easy backend development, such as Laravel, CakePHP, etc.
Node.js also has popular frameworks like Express, Meteor, and DerbyJS, etc.
Execution Speed
PHP execution speed is slower than Node.js.
Node.js is faster than PHP and lightweight too.
Web Server
PHP needs Apache web server to execute the code.
Node.js doesn’t need any web server to execute. It runs in its own environment.
Compatibility with other languages
PHP can contain HTML, JavaScript, CSS, and even plain text.
Node.js can contain only JavaScript.
Used by
Facebook, Wikipedia, Yahoo, Flickr, and WordPress, etc., are using PHP.
IBM, GoDaddy, NetFlix, LinkedIn, Paypal, and Walmart are the adopters of Ndoe.js.
Complexity
PHP is simpler to use than Node.js.
Node.js is not too complex, but need more lines of code and callback functions.
Basic syntax
echo ‘Hello PHP’;
Console.log(‘Hello Node.js’);
Module
A developer needs to download and install PHP manually. It doesn’t come in bundled with module.
It comes prepackaged with the NPM package management system and its registry.
Performance
PHP is fast, but slower than Node.js due to the database, third-party request, and file system.
Node.js is faster due to its non-blocking mechanism.
PHP stands for Hypertext Preprocessor, which is an open source scripting language. It is a server-side scripting language and a powerful tool for creating a dynamic and interactive website.
PHP is an interpreted language, so it doesn?t need compilation. It is specially designed for server-side scripting, which executes on the server. PHP can be easily embedded with HTML files.
Note: PHP is mainly used to develop server-side applications.
It has several advantages that are given below:
PHP code can be executed on different platform such as Windows, Linux, UNIX, Solaris, etc.
It is easy to use and learn.
PHP is an open source language, which means, it is available for free of cost.
In general, PHP is cheap, cross-platform, fast, and reliable to develop web applications.
What is JavaScript?
JavaScript is a client-side scripting language. It is designed to create a network-centric application. JavaScript is a lightweight and case-sensitive language that has object-oriented capabilities.
We can design web pages using HTML, but cannot run any logic like arithmetic operations, check any conditions, or looping statements, etc., so to achieve this at client-side, JavaScript is needed.
JavaScript also has several advantages that are given below:
JavaScript is very fast as a JavaScript code executes immediately within the client browser.
JavaScript can easily embed with HTML, AJAX, and XML.
JavaScript supports all modern browsers and provides the same result on all.
It provides immediate feedback to the user if they forgot to enter some details.
Difference between PHP and JavaScript
PHP and JavaScript both are used for different purposes. As we have discussed earlier that PHP is a server-side script, whereas, JavaScript is a client-side script. Below are some differences between PHP and JavaScript has given:
PHP
JavaScript
PHP is a server-side scripting language.
JavaScript is a client-side scripting language.
PHP performs all the server-side functions like authentication, building custom web content, handling request, etc.
JavaScript is designed to create an interactive web application without interacting with the server
PHP can combine with HTML only.
JavaScript can combine with HTML, AJAX and also with XML.
PHP is used for back-end purpose only.
JavaScript is used for both front-end and back-end.
PHP is easy to learn.
JavaScript is complex to learn.
PHP is a multi-threadedlanguage, which means it blocks input/output to do multiple tasks concurrently.
JavaScriptis single-threaded, i.e.,event-driven, which means it never blocks, and everything runs in concurrent order.
In PHP, the code will be available and viewed after it is interpreted by the server.
A JavaScript code can be viewed Even after the output is interpreted.
It is synchronous by nature and waits for I/O operation to execute.
JavaScript is asynchronous by nature and does not wait for I/O operation to execute.
MVC is a software architectural pattern for implementing user interfaces on computers. It divides a given application into three interconnected parts. This is done to separate internal representations of information from the ways information is presented to, and accepted from the user.
MVC stands for “Model view And Controller“.
The main aim of MVC Architecture is to separate the Business logic & Application data from the USER interface.
Different types of Architectures are available. These are 3-tier Architecture, N-tier Architecture, MVC Architecture, etc.
The main advantage of Architecture is Reusability, Security and Increasing the performance of Application.
Model: Database operation such as fetch data or update data etc.
View: End-user GUI through which user can interact with system, i.e., HTML, CSS
Controller: Contain Business logic and provide a link between model and view.
Let’s understand this MVC concept in detail:
Model:
The Model object knows all about all the data that need to be displayed.
The Model represents the application data and business rules that govern to an update of data.
Model is not aware about the presentation of data and How the data will be display to the browser.
View:
The View represents the presentation of the application.
View object refers to the model remains same if there are any modifications in the Business logic.
In other words, we can say that it is the responsibility of view to maintain consistency in its presentation and the model changes.
Controller:
Whenever the user sends a request for something, it always goes through Controller.
A controller is responsible for intercepting the request from view and passes to the model for appropriate action.
After the action has been taken on the data, the controller is responsible for directly passes the appropriate view to the user.
In graphical user interfaces, controller and view work very closely together.