Php tutorial and examples

PHP Introduction

Before you continue you should have a basic understanding of the following:

If you want to study these subjects first, find the tutorials on our Home page.

What is PHP?

  • PHP is an acronym for «PHP: Hypertext Preprocessor»
  • PHP is a widely-used, open source scripting language
  • PHP scripts are executed on the server
  • PHP is free to download and use

PHP is an amazing and popular language!

It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!
It is deep enough to run large social networks!
It is also easy enough to be a beginner’s first server side language!

What is a PHP File?

  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code
  • PHP code is executed on the server, and the result is returned to the browser as plain HTML
  • PHP files have extension » .php «

What Can PHP Do?

  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data

With PHP you are not limited to output HTML. You can output images or PDF files. You can also output any text, such as XHTML and XML.

Why PHP?

  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free. Download it from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side
Читайте также:  Sys argv python path

What’s new in PHP 7

  • PHP 7 is much faster than the previous popular stable release (PHP 5.6)
  • PHP 7 has improved Error Handling
  • PHP 7 supports stricter Type Declarations for function arguments
  • PHP 7 supports new operators (like the spaceship operator: )

Источник

PHP Tutorial

This PHP tutorial, whether you’re a beginner or a professional, our tutorial is designed to provide you with in-depth knowledge of the PHP scripting language.

PHP Tutorial

With our PHP tutorial, you’ll learn all the important topics, including control statements, functions, arrays, strings, file handling, form handling, regular expressions, date and time manipulation, object-oriented programming in PHP, mathematical operations, working with PHP and MySQL, integrating PHP with Ajax, harnessing the power of PHP with jQuery, and more.

What is PHP?

The term PHP is an acronym for Hypertext Preprocessor . It is an open-source, interpreted, object-oriented server-side scripting language that is used for web development. PHP is developed by the Rasmus Lerdorf in 1994 with the very first version of PHP that simply designed to set the Common Gateway Interface (CGI) binaries, which are written in C programming language. The latest version of PHP is PHP versions 8 which is released on November 24, 2022. It can be easily embedded with HTML files. HTML codes can also be written in a PHP file. The PHP codes are executed on the server-side whereas HTML codes are directly executed on the browser.

Example: Simple program to print “Hello world!” message on the screen.

PHP

Источник

PHP Tutorial

PHP Tutorial

The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. This tutorial helps you to build your base with PHP.

Why to Learn PHP?

PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.

Читайте также:  Обобщенный алгоритм евклида python

PHP is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Web Development Domain. I will list down some of the key advantages of learning PHP:

  • PHP is a recursive acronym for «PHP: Hypertext Preprocessor».
  • PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
  • PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time.
  • PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support for Java and distributed object architectures (COM and CORBA), making n-tier development a possibility for the first time.
  • PHP is forgiving: PHP language tries to be as forgiving as possible.
  • PHP Syntax is C-Like.

Characteristics of PHP

Five important characteristics make PHP’s practical nature possible −

Hello World using PHP.

Just to give you a little excitement about PHP, I’m going to give you a small conventional PHP Hello World program, You can try it using Demo link.

Applications of PHP

As mentioned before, PHP is one of the most widely used language over the web. I’m going to list few of them here:

  • PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
  • PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send data, return data to the user.
  • You add, delete, modify elements within your database through PHP.
  • Access cookies variables and set cookies.
  • Using PHP, you can restrict users to access some pages of your website.
  • It can encrypt data.

Audience

This PHP tutorial is designed for PHP programmers who are completely unaware of PHP concepts but they have basic understanding on computer programming.

Читайте также:  Remove line breaks in string php

Prerequisites

Before proceeding with this tutorial you should have at least basic understanding of computer programming, Internet, Database, and MySQL etc is very helpful.

Источник

PHP Syntax

A PHP script is executed on the server, and the plain HTML result is sent back to the browser.

Basic PHP Syntax

A PHP script can be placed anywhere in the document.

The default file extension for PHP files is » .php «.

A PHP file normally contains HTML tags, and some PHP scripting code.

Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function » echo » to output the text «Hello World!» on a web page:

Example

My first PHP page

Note: PHP statements end with a semicolon ( ; ).

PHP Case Sensitivity

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

In the example below, all three echo statements below are equal and legal:

Example

Note: However; all variable names are case-sensitive!

Look at the example below; only the first statement will display the value of the $color variable! This is because $color , $COLOR , and $coLOR are treated as three different variables:

Example

$color = «red»;
echo «My car is » . $color . «
«;
echo «My house is » . $COLOR . «
«;
echo «My boat is » . $coLOR . «
«;
?>

PHP Exercises

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

Оцените статью