Illustrated tutorial on PHP. Personal experience as proof: the PHP programming language is the main one on the Internet

Internet in modern world occupies an increasingly stronger position. About 15 years ago, to access the network you needed expensive equipment and a lot of money to pay bills. Nowadays anyone can get on the Internet for pennies if they have at least mobile phone. More and more services are moving to electronic form. From a means of communication and information exchange, the Internet is turning into handy tool to do business and make money.

Every day, millions of users visit their favorite sites, download email, files or news, play online games, conduct company business, or simply communicate in chat rooms, blogs and forums. Most of these users have never thought about how it all works, who creates new sites and services, how and with what help.

This electronic textbook designed for those for whom it is not enough to simply surf the Internet. For those who want to learn how to create their own websites and keep up with the latest trends in programming and design.

General principles

Before you start learning a language, you need to clearly define the terminology and understanding general principles operation of the Internet. Let's start with the principles of the network and sites.

The Internet consists of a huge number of interconnected computers, routers and other hardware needed for proper operation. Each element of the Internet (node) has a unique descriptor - an IP address. Knowing the IP address of a node, you can try to connect to it, and with a little skill you can determine who this address belongs to and in what region of the world it is located. IP addresses are usually written as four groups of numbers separated by dots, for example

192.168.100.003 or 10.10.0.123

Agree, remembering the addresses of all frequently visited pages is not an easy task. Therefore, there are special DNS server(Domain Name Resolution), which stores mapping lists of IP addresses and symbolic names. It is thanks to these servers that the user always gets to the desired IP address by typing only the page name in the browser.

After we have entered the name of the desired page into the browser line, the browser independently receives from DNS IP address the desired server and sends it to this address special request to receive a page (HTTP request). Running on a server specialized program(the so-called Web server) processes this request and returns the required page to the browser.

Obviously, all actions for displaying a page can be clearly divided into two categories: those performed on the client side ( client code or front-end) and executed on the server side ( server code or back-end). Moreover, the server knows nothing about the current state of the client, and the client knows nothing about the current state of the server. When developing exchange algorithms, you must always remember this and timely transmit the necessary data describing the state or required action.

Depending on the place of application, the means of implementing the parts also differ. On the client side, typically only HTML, JavaScript (AJAX), CSS and Flash are used. Server-side developers are less strapped for money, because... most of existing languages allows you to create or describe HTML pages. The most widely used today are Java, Perl, PHP, Python, Ruby, C# and VB.NET. Each of them has its own strengths and weak sides, so the developer must make a choice based on the tasks facing him.

Why PHP?

Exists a large number of languages ​​that can be used when creating websites. Some languages ​​have existed for a long time and are successfully used (or no longer used). Some languages ​​are still very young and have not yet received widespread use. Lastly PHP time became a leader in popularity, for several reasons:

  1. Simplicity. The language is very easy to understand, especially for novice programmers.
  2. Development speed. Thanks to its simplicity and intuitiveness, PHP allows you to create quite complex websites very quickly.
  3. Availability of libraries Exists great amount ready-made examples and class libraries. Hundreds of libraries have been created and tested to significantly simplify the life of a developer.
  4. Support Almost every server on the Internet supports PHP
  5. Safety PHP allows you to create truly secure websites thanks to built-in support for data encryption during storage and transmission.

However, PHP pays for its benefits with some limitations. For example, use PHP to access system functions very inconvenient compared to Perl or Python (which is why many system administrators love Perl so much). There are several other limitations that we will talk about when studying the relevant sections.

Language PHP programming - Training course - Savelyeva N.V. - 2006.

PHP is currently one of the most popular languages ​​for implementing web applications. This course dedicated to studying its fundamentals. The emphasis is on practical use acquired skills.
The PHP language was created to solve a specific practical problem on the Internet (which one can be found out by reading the first lecture of the course). We will also try not to be distracted too much by theoretical reasoning, and will strive to solve some specific task in each of the lectures. Most examples are taken from real life existing system: virtual museum of the history of computer science. The first part of the course is devoted to studying the basics of syntax and control structures. After this, client-server technology is considered as the main application area of ​​the PHP language. Then we move on to studying the most useful built-in functions in our opinion and solving with their help practical problems. Although the object model in the PHP language is not the richest, its fundamental presence allows you to naturally describe object models data. As a basic model, the document model of a virtual computer science museum will be considered. After this, a number of applied aspects will be considered: working with file system, with a database, strings, sessions, DOM XML - all this will allow you to consider key tasks practical use language.

PHP, MySQL for beginners - Andy Harris - 2005.

This book will help you learn how to program in PHP and create databases in MySQL. If your goal is to write programs for web servers, then this book is for you. You will learn all the basic concepts of programming languages, in particular, learn the commands and syntax of the PHP language. You will also learn how data is used in modern environments, in addition to all this, you will also learn the programming process itself.


Download and read PHP, MySQL for beginners - Andy Harris

PHP - Learning by Example - Kuharchik A.

PHP - Learning by Example - Kukharchik A. - 2004.

The basics of PHP, a popular language for writing scripts for Web pages, are presented in a simple and accessible way. By completing simple examples, the reader will be able to master the basics of programming in PHP, create a dynamic page, a site visit counter, a voting system, address book, Online store. Described typical mistakes use of scripts, as well as ways to correct them. The book contains code snippets that you can use to create your own projects.

Intended primarily for beginners, but can also be useful for experienced programmers using PHP.

Bootstrap framework: fast adaptive layout

Step-by-step video course on the basics adaptive layout in the Bootstrap framework.

Learn how to typesetting simply, quickly and efficiently using a powerful and practical tool.

Layout to order and get paid.

Free course "Site on WordPress"

Do you want to master CMS WordPress?

Get lessons on website design and layout on WordPress.

Learn to work with themes and cut layouts.

Free video course on drawing a website design, layout and installation on CMS WordPress!

*Mouse over to pause scrolling.

Back forward

PHP Fundamentals: An Overview for Beginners

PHP has been consistently on the list of the most popular programming and web development languages ​​for many years. Of course, there are other languages, but the ubiquity of websites based on WordPress engine largely served as an additional impetus for an even greater increase in popularity of this language.

What is PHP?

PHP stands for Hypertext PreProcessor(something like an "HTML preprocessor").

What does this mean? Let's start a little from afar: there are two types of languages. One type is called "client", and the other - "server".

It means that client languages ​​work in each individual's browser. A typical representative of client languages ​​is JavaScript, which you have probably heard about and the results of which you have seen more than once.

If you want to learn more about JavaScript, then check out the material.

All actions and commands that we give, say, to JavaScript, are executed by the browser, which means that the same code written by us is processed in one case by the browser Internet Explorer, in another - Firefox, in the third - Opera, in the fourth - Google Chrome, i.e. the browser that everyone uses special person to view our page.

The browser thus has alternative name - client.

In case of server-side languages(to which PHP belongs) we see a different picture.

Our website is always located on some server, i.e. powerful computer, specifically designed to host many people's websites.

All commands and scripts written in PHP are executed on the server, and nothing else. After the PHP script is executed on the server, the server “gives” the result of its work, which we see in the browser.

It is important to understand the following point: by the source code of the web page, which can be viewed in any browser through an option like "Source pages" it is impossible to determine whether PHP was used to create a given page or not.

It is impossible to do this precisely because PHP scripts are processed on the server, and a ready-made, processed version is transferred to the browser. Basically just HTML code.

The difference compared to regular static HTML pages is one additional stage code processing.

In the case of an HTML page, there is only one step: The browser processes the HTML code, i.e. page layout in accordance with certain rules, as a result of which we see the web page in its normal form.

In the case of a PHP page, there are two steps: first the so-called PHP interpreter(handler) executes the PHP code (as a result, a simple HTML code is obtained), and after that the browser processes the result of this processing, i.e., in fact, the very stage that is unique in the case of HTML is executed. page.

In general, PHP works great when paired with HTML. Moreover, you can insert PHP code into HTML code, and with using PHP output HTML markup. It's important to remember this simple point: It doesn't matter how complex your PHP code is, it will eventually end up as plain HTML.

Why use PHP?

HTML is 100% static. By embedding PHP code into our pages, we can ensure that the content of the same page was different depending on certain conditions(dynamic pages). Over the many years of its existence, the PHP language has established itself as an excellent solution for creating dynamic websites.

Is PHP similar to other languages?

Yes. PHP is similar to ASP.NET, Perl, JavaScript, C#. You may not know any of them now, but learning PHP will give you more confidence in mastering other languages ​​in the future.

What do you need to get started?

For full-fledged work with PHP on your computer you need the following things:

1. Apache web server(it is used in most cases);
2. Database Management System (DBMS) MySQL (the content of the site is stored in the database);
3. Installed PHP interpreter;
4. Text editor, in which you will write code;
5. Browser.

Now a little more about the first three points.

1. Web server is designed to simulate on your computer the very server on which your website will then be hosted on Internet hosting. This is necessary so that you can write any PHP scripts on your computer and watch how they work, make changes and edits to them. In a word, this is necessary for so-called debugging.

2. MySQL DBMS needed to store information that will be on your website. In the case of HTML pages, all the content of the site is located directly in them. Each page contains a certain amount of information (content).

At using PHP For the purpose of storing useful information content of the site, a database is usually used. In the vast majority of cases this is MySQL.

3. PHP interpreter is a kind of program that processes PHP code on a web server. Without it, we will not be able to execute our PHP scripts and see the result of their work.

How to install all these components on your computer?

Exists good decision, which greatly simplifies this process and does not require you to have any knowledge in setting up a web server, MySQL and PHP interpreter.

This special set Denwer, which already includes all three components. It installs on your computer as regular program and is ready to work without preliminary settings.

Denwer is ideal solution in the vast majority of cases, and for beginners it will be a lifesaver, as it allows you to start developing websites in PHP without having to learn a bunch additional information on setting up a web server, MySQL DBMS and PHP interpreter.

Basics

In order to tell the server to process PHP code, you must use the following syntax when adding PHP to an HTML document:

Opening a block of PHP code is indicated as ", and closing - "?>" . Now let's change our code as follows:

Please note that in in this example we wrote everything in one line. Spaces and line breaks do not play a role here and will not affect the final result.

In the example we give the server the command echo(command for displaying information on the screen) and indicate that we want to display the phrase This is PHP in action. Each command in PHP is separated from the previous one by a semicolon at the end of that command.

PHP is more strict about strict adherence to syntax and will not forgive you for the absence of a semicolon, brackets, quotes, etc., as might be the case with HTML. PHP in this case will display a message about syntax error, which needs to be corrected and will indicate the line where this error was made.

By the way, in in this case we might not have used a semicolon at the end of the command, since it is the only one we have in this case (command). However, it is always better to stick good practices when working with code.

Declaring Variables

Variable in PHP- this is a kind of container that can contain certain information. In order to create such a “container”, we need to name it and indicate what should “lie” in it. This is done using a sign "$" , which means we are dealing with a variable. Let's put it in a variable named test phrase This is PHP in action.

The result of processing this code will be exactly the same as in the previous example. The phrase will simply be displayed on the screen This is PHP in action. However, before this we directly output this phrase, but now we have added this phrase to a variable test, after which they gave the command to display the value of the variable on the screen test.

How can we add some more text or other information to display on the screen?

Let's look at this with the following example:

As you can see, after outputting the variable test there is a space, then a period, then a space again. After this, quotes open, first there is one space, and then a sentence My name is Dmitry Naumenko., followed by closing quotes.

Let's go through the steps and see what is needed here and why.

After outputting the variable test we seem to be “adding” to an already existing output additional text. This is done using the dot symbol (.) .

The dot symbol means addition in PHP, but not addition of numbers, but addition precisely text information, like the one we work with. After the period, we indicate in quotation marks what exactly we want to add to the conclusion, and write a new sentence.

Note that there is a space after the opening quotes. When displayed on the screen, it will be saved, so our phrases will not merge. Those. we will get you output:
This is PHP in action. My name is Dmitry Naumenko.

If you remove that space, you get:
This is PHP in action. My name is Dmitry Naumenko.

I would also like to draw your attention to the spaces on both sides of the addition point. These spaces do not play any role and are used only for clarity and ease of perception. The following code will give us exactly the same result:

Therefore, write in the way that is most convenient for you in this case.

Inserting comments in code

First question - "What are they even for?"

Comments are needed so that you can make notes, notes, explanations, etc. in your or someone else’s code. while working with the code. Now it seems to you that everything is clear and obvious. As long as you remember perfectly well why this variable is needed and what that function does.

Not much time will pass and without comments you will hardly be able to understand even your own code, not to mention other people's scripts. Therefore, proper use of comments is an urgent need.

Typically used in PHP two types of comments:

Of course, comments only work within blocks of PHP code And ?> .

Outputting HTML using PHP

As I mentioned earlier, PHP and HTML work great together. Just because we're inside a block of PHP code doesn't mean we can't display text in a paragraph or in bold.

This is the text in bold."; ?>

As you may have guessed, the result of this code will be the output of this line in bold to the browser.

Create the first function

First of all, a few words about what a function is.

Function- this is a kind of mini-program that performs a certain useful work and gives us the result.

It makes sense to use functions in cases where you need to perform similar, template actions. In this case, we write such a mini-program, which significantly reduces the amount of code and, accordingly, our efforts.

The syntax when creating a function is as follows:

Let's say if we want to write a function that calculates the sum of the numbers 10 and 5, we can do this:

We create a function called sum and in its body we indicate that it should display the sum of the numbers 10 and 5. After this, we call the function sum. Calling a function essentially means executing it.

In this example we do not use any arguments (see function syntax above). What are arguments and what are they needed for, we will look directly at the example. Let's modify the code that we have, making it more flexible and functional:

Now when creating a function sum we indicate two arguments in parentheses, separated by commas - $slagaemoe1 And $slagaemoe2. In the body of the function, we add and display not specific numbers, but the values ​​of variables $slagaemoe1 And $slagaemoe2(i.e. these same arguments).

Now we just need to call the function, passing it two arguments in parentheses that it “expects”. We specify the numbers 10 and 5, resulting in 15. By passing the function sum other numbers, of course, we will get a different answer.

I hope that this review helped you understand what PHP is and what it is needed for, what advantages it has over static HTML, and how you can use some of its simplest features.

Dmitry Naumenko.

P.S. Do you want to move further in mastering PHP? Pay attention to premium lessons on various aspects of website building, including PHP programming, as well as free course to create your own CMS system in PHP from scratch. All this will help you master this powerful web development language faster and easier:

Did you like the material and want to thank me?
Just share with your friends and colleagues!


Good day, dear readers of my blog. I heard somewhere that every person must go through writing poetry in their life. The situation is changing and now every second person is thinking about writing code and creating their own website. Many merge at the moment, others cannot decide on the engine. If you finish reading this article and proceed to training according to my recommendations, I am almost sure that you will succeed.

The topic is quite complex. Today we will talk about how to write a website in PHP from scratch. Let's take a closer look at what these treasured three letters mean and you will learn about the best ways not only learn, but also really understand PHP.

What is PHP?

It’s a little strange to start an article with this question, because it is assumed that you already know everything and are therefore ready for difficulties. But, my blog is intended for beginners. Be lenient, let's repeat the information.

In simple and accessible words, php is a programming language specifically designed for creating a web application script that runs on a web server. It is quite a popular programming language as 85% of websites use it.

The peculiarity of this language is that it is universal, easy to learn and opens up your opportunities not only as a programmer, but also as a businessman. As a result, you will be able to write and develop your projects yourself. Without anyone's help.

Learning effectively

Many people have started learning this language, but few reach the end. For effective learning, the first thing you need to do is find a source of information, a book, training course or video, but more on that later.

Then we need to download the compiler. This is a program that reads your script line by line as an instruction and executes it.

The most common compiler is Denver - simple and free package necessary programs, with which you can write scripts. If you ask my opinion, then I would advise you to download Open Server. It is now gaining momentum. It is a cut above Denver and will be more comfortable for you to work in.

What do these packages do? They allow you to work on it as a server. There is no need to download anything right now. You will hear more than once about useful software from this series in any training course, and you will need it.

The essence of effective learning is that after completing the lesson, you should try to put everything into practice. If theory is supported by practice, then within a few weeks you will have basic language skills.

Books for learning

Let me tell you, I'm not a fan of books. When we're talking about about Internet technologies. It's like explaining to a Maasai person what wi-fi is. No amount of pictures will help you understand everything properly. And yet, I want to provide you with a small list of books on PHP for dummies that are rated among professionals.

I would like you to really achieve your goal and if you think this training option will suit you better, I will be happy to provide information.

PHP and MySQL. Web Application Development - An excellent book that is suitable for a beginner. First of all, the author will show you how to set up Apache (HTTP server), PHP and MySQL (database), then he will tell you how to choose a code editor. The book covers: the syntax of the language, the most useful features, creating your own engine and a number of other functions.


In general, nothing surprising, right? But nevertheless, this is a real textbook with unique information, which you won't find anywhere else. This is already the fifth edition, that is, there will be no outdated information. The book was published in 2015. In order to start getting acquainted with the code yourself, this is it.

HTML, JavaScript, PHP and MySQL. Gentleman's set for webmaster – This is a more detailed tutorial on learning PHP. It touches on several other useful ones without which full creation web applications are not possible.

Easy to read, suitable for self-study and student learning. The author touches on such topics as: PHP basics, dynamic page formation when CSS help(cascading style sheet), database administration, creation dynamic pages using JavaScript.


We create dynamic websites using PHP, MySQL, JavaScript, CSS and HTML5 this book I would advise more advanced readers who already have basic skills HTML layout. If you have ever studied this and still remember the basic principles then this book is for you.


PHP and MySQL. From beginner to professional – and our review ends with Kevin Yank’s book, in which the author places a strong emphasis on creating web applications with a database.


The book is very easy, perfect for self-study.

Video from YouTube

From my own experience, I will say that learning PHP from YouTube videos is quite difficult. Even though they seem simple. Unlike Photoshop tutorials, which I love, learning programming languages ​​on YouTube is simply impossible. Even a video that is only 15-20 minutes long causes a lot of inconvenience.

Such videos can discourage you from typing code yourself. Why, if the author has already done everything for you: typed, launched, pointed to specific example how does it all work? As a result, it is almost impossible to remember anything.

Training course

In my opinion, this is an ideal training option. It's great when a specialist works with you.

Each lesson is accompanied by comments; you can ask questions to experts, calmly discuss and resolve unclear points. You don't have to surf the Internet looking for information. Everything will be chewed and put in your mouth, all that remains is to use it.

You will be given a task and monitored to see how correctly you complete it.

I can recommend you course on Netology . This training center is prized among professionals, and in just two months you can learn everything you need to know. Recruitment to the group occurs constantly.

Don't worry if you don't understand something. This is what the course is designed to help you learn. This is real step-by-step instruction for newbies. Don't believe me? Download full program course from the official website and you will see for yourself.


If you dream of learning how to create websites without , yourself and with PHP, then this is the best option for you.

From the author: Is it necessary to know the PHP programming language? If you are going to throw in your lot with website building, you will have to. Even if you really don’t want to! Why is that? We will try to answer all the common “whys” associated with this language in our material.

The solution that “holds” the Internet together

This is exactly how one of my acquaintances, who has been creating Internet resources for more than a decade, described PHP. And he’s right, probably 200% percent (or maybe more).

The very history of the emergence of this language suggests that it was born to “blind” the current version of the Network to which we are so accustomed. This is probably why some people still cannot realize its power, even after learning the basics of PHP programming.

Proving the role of PHP in creating the Internet is a thankless task. Here, as they say, supporters of others can begin to speak out server languages. They say that the “hypertext preprocessor” (as the abbreviation PHP stands for) has already outlived its usefulness. Many of its functions are implemented even in...

Well, shouting and waving your arms, extolling your programming language, which you specialize in, is a simple matter. But the best “evidence” indicating the demand for PHP is its prevalence.

Next rating program languages, compiled by TIOBE specialists last summer, tells us that PHP has been consistently among the top for several years. Haven't you started looking for a tutorial on the PHP programming language yet? You'll be running soon.

If you are wondering why Java has jumped so much, then the answer is: thanks to the Android mobile operating system, applications for which are developed in this language.

Own rake

Back in the early 2000s, I was engaged in “research” in the field of programming. I kept trying to figure out which “party” of developers I should join, which discipline I should devote my life to studying.

In principle, I did not consider PHP as a programming language for beginners. He seemed too confused. Here's the other thing about ASP.NET: a commercial language based on C#. Oh, what castles in the air I built back then! And there were all the prerequisites for this:

The technology was developed by such a “thought giant” as Microsoft.

Availability of specialized software – powerful editor Visual Studio.

Extensive and well described documentation.

Hope for a “healthy” future.

ASP.NET, unlike PHP, was much easier for me. Visual Studio has automated a large number of server-side scripting operations. For example, thanks to the excellent visual editor it only took a few minutes to create a web page. By dragging and dropping controls and styling them in the editor, you could make a website in less than an hour!

But the PHP programming language from scratch didn’t work out for me right away. Honestly, I tried to make friends with him (I had to pass the exam somehow). But when studying its basics, it seemed callous and even cold to me.

In general, I took up ASP.NET. I created my first website. Well, everything seems to be working in the development environment. Cross-browser compatibility checked in several popular browsers. I think it’s time to “fight.” So to speak, show your “brainchild” to the whole country (at least). This is where the “rakes” turned out to be.

My attempts to find hosting with ASP.NET support on the RuNet were never successful. There were, of course, several paid platforms, but the prices for hosting a website on them were clearly not “student” prices.

Somehow I dug up in Burzhunet free option hosting (by the way, sponsored by Microsoft). Well, I clicked, enjoyed the breadth of my thoughts, but things didn’t go any further. And all due to the fact that most of the sites were already made in PHP.

Once you decide and understand exactly what you are ready to study PHP language programming, look for a tutorial for beginners “to suit your needs.” The main thing is that you understand what the author of the publication wants to convey to his readers. Immediately get ready to pay a good amount of money for quality literature.

But it's better to apply A complex approach- add also sensible. This will allow you to hone your skills right away practical examples. And my advice to you is to do less copy-pasting code! I’ll explain why now.

When you type example scripts yourself, you will quickly get used to it and remember the features PHP syntax. As for literature, choose a tutorial with the basics of programming in PHP. And it is advisable that the author post the code of all the examples given on his resource on the Internet.

Also, immediately before starting training, download and install Open Server. This software package includes all the environments you need to write and test code.

Well, let me take my leave for today. Forgive (if anything) for the excessive overview of the content of the article, but this is necessary to understand the features of this language (after all, it is server-based). I wish you to quickly grasp the basics of the PHP programming language and start real coding!