Learning php with examples. Fundamentals of PHP Basics: An Overview for Beginners

During this course, you will learn the basics of PHP programming and explore the possibilities of this language. This PHP course is designed for beginners and contains detailed text and video instructions - choose what you like best.

In the course, everything is studied in great detail - learning begins with how PHP works in general. It tells about modern tools and approaches. And, of course, homework is given, which I personally check. Here we will install a local web server, and learn how to work in a code editor, and, of course, write our first programs in PHP.

This course will allow you to master the basic principles in programming, which no future developer can do without. Here you will get the necessary foundation that will allow you to go further, learning more interesting and complex topics in programming.

What is PHP for?

Knowledge of HTML allows you to get an idea of ​​how to create websites. And even gives the opportunity to independently develop Internet resources. However, the use of this markup language is limited due to the static nature of the pages created with it. In particular, it is used in most cases for the development of business card sites. The thing is that if you need to make any changes, you need to edit each page separately, and if the resource has several tens or hundreds of them, such a process will not only be tedious, but also stretched out in time.

The use of PHP (acronym for PHP: Hypertext Preprocessor "hypertext preprocessor") allows you to optimize site administration, a scripting programming language that allows you to create dynamically filled web pages. Its use makes it possible to make the resource truly interactive, and the process of managing the site - simple and less costly in terms of effort. Online PHP courses from WebShake help you master the basics of a scripting language from scratch, learn how to create dynamic resources that are easy to modify and maintain.

Our text materials and video tutorials are designed to be understandable to every user who wants to learn web programming. And homework, placed at the end of each topic, will allow you to consolidate the knowledge gained and hone their application in practice.

Benefits of a scripting language

Hypertext Preprocessor is primarily distinguished by its practical orientation. The rich functionality of PHP allows you to effectively solve the widest range of tasks. And ease of use makes it possible to do it quickly and with a minimum of effort. Our free PHP course for beginners helps you master this scripting language, which is by far the most in demand and is used to create a huge number of Internet resources (including popular social networks and blogs).

The traditional nature of PHP (due to borrowing a number of constructs from C and Perl and combining the advantages of these languages), along with the intuitive accessibility and universality of the syntax, makes the learning process easy (especially for people familiar with the basics of programming). If, however, some difficulties arise in the process of familiarizing yourself with the course, I am ready to answer any questions that you can ask in the comments to the lessons.

The high speed of script execution increases the efficiency and relevance of PHP, and the ability to integrate with other languages ​​(in particular, HTML, JavaScript) allows you to customize the Hypertext Preprocessor to the needs of a particular web developer.

PHP Features

Website development using this scripting language allows you to:

  • Reduce the resource requirements of the web page. The web application takes up less space, becomes “lighter”, which means it opens faster.
  • Significantly simplify the process of managing a web page, making changes. Static sites do not meet the realities of today, as they simply do not keep up with what is happening around. The inability to keep up with the times ultimately affects attendance.
  • Provide an effective analysis of the site (keep traffic statistics, etc.).

The efficiency of Hypertext Preprocessor is appreciated by the largest companies. Our PHP course for beginners allows you to gain the necessary skills and knowledge to build a successful career in the field of web development without being distracted from work or study.

Here is a short guide to PHP language for dummies in several parts. I guarantee you will be able to write your first working PHP code after reading this series of articles (or in the process of reading). PHP is one of the easiest programming languages ​​to learn, it is a server-side (server-side) scripting language (interpreted language).

It is used to create web projects. Can be used directly in HTML code. And although the result of the script is often displayed directly in the client's browser, only one browser is enough for PHP to work. That is, you will not be able to run the index.php file directly in the browser, as you probably already did with the index.html file. PHP scripts and web pages created using PHP require a web server to run.

If you don't have a hosting site for your site yet, then I recommend experimenting with PHP scripts on a local server designed for testing projects. To organize a local server in the Windows operating system (WAMP, Windows-Apache-MySQL-PHP), packages can be useful: Denver, XAMPP, AppServ, OpenServer, etc. After installing these packages, you will receive a server already configured and ready for use, and it will be controlled through a convenient menu of the program itself. Also, there are separate implementations of APACHE, MySQL and PHP for the Windows operating system, but you will have to configure them yourself through the configuration files and there will be no menu with checkmarks. To start, restart and stop such a server, you can use batch files *.bat or *.cmd (batch file) with commands to start, restart or stop the APACHE and MySQL services. The third and most difficult option for a beginner is a virtual machine with the Linux operating system installed and configured (LAMP, Linux-Apache-MySQL-PHP). Ready-made images of such "virtual machines" are often found on the Internet, so you may only need knowledge of setting up programs like VirtualBox or VMware.

Getting Started with PHP Programming for Dummies

  1. PHP code should be placed in the index.php file, the file itself should be placed in the root directory of the site located on the web server.

  1. All PHP code must be enclosed between descriptorsor an abbreviated version, but the web server may not be configured to use a shortened version of this entry, so the first option is preferred.
  2. Inserted PHP code can be anywhere in the HTML code.
  3. Commenting in PHP code is done like this:
// single line comment # another version of a single line comment /* multiline comment */
  1. To view your code, open a web browser and type in the address bar: http://localhost/www/MyEX/index.php

Printing Data to the Screen with PHP for Dummies

  1. Outputting data to a window (the client area of ​​a web browser) using PHP can be done using the echo statement. This operator allows you to display data of various types: numbers, character strings, etc.
  2. Output statement syntax:
echo element1, element2, element3, ..., elementN
  1. String data is enclosed in double or single quotes. In double quotes, the code is interpreted by PHP. Anything enclosed in single quotes is output without any interpretation. Example:
< ?php $x="PHP"; //присвоение значения переменной echo "Привет","всем"; echo " "; echo "

$x code example

$x code example

  1. To display more detailed information about a variable, which may be needed when debugging a program, use the var_dump() function. Its syntax is:
var_dump(list of variables);
  1. The variable list specifies one or more variable names. This function does not return anything. Example:
$x=12.56; var_dump($x);
  1. Less informative than var_dump() , the function to dump information about variables is:
print_r(list_of_variables);
  1. For array variables, this function outputs a list of the form index => element.

PHP language variables for dummies

  1. Variables are containers for storing data. The data stored in a variable is called the value of that variable.
  2. A variable has a name, a sequence of letters, numbers, and underscores without spaces or punctuation, and must begin with a dollar sign ($) followed by a letter or underscore.
  3. Valid variable names: $_tel, $tmp, $my_, $address_234_45.
  4. Incorrect variable names: $234tel, my address, $tel:234.
  5. PHP is a case-sensitive language with respect to variable and constant names. However, keywords can be used in any case.

PHP Data Types and Data Transformation for Dummies

Data type Example Description of values
String or character (string) "Hi all"
"123456"
"25 rubles"
A sequence of characters enclosed in quotation marks
Integer, numeric (integer) -234
25
0
A number or sequence of digits that can be preceded by a number sign
Numeric floating point (float) 5.47
21.4
35E-3
A number with a fractional part (35E2 means 3500)
Boolean (boolean, boolean) true
false
This type has two values: true (true, yes), false (false, no)
NULL null This data type has one value - null
Array This data type has one set of values ​​that can be of different types.
Object Program object defined by its properties
  1. In order to find out what type of variable, you need to use the function:
gettype(variable_name);
  1. To explicitly set the type, you can use one of two methods:
Variable_name=(int) 12.45 //result 12 Settype(variable_name, "type")< ?php $x="PHP"; $s=gettype($x); echo $s, " "; settype($e,"integer"); $s=gettype($e); echo $s, " "; $d=(int)24.4; $s=gettype($d); echo $s, " ", $d; ?>

PHP constants for dummies

  1. A constant is a named value that does not change during the execution of a program (script).
  2. Unlike variables, you cannot change the values ​​of constants that were assigned to them when they were declared. Constants are useful for storing values ​​that should not change while the program is running. Constants can only contain scalar data (boolean, integer, float, and string types).
  3. In PHP, constants are defined with the define() function. Here is its syntax:
define($name, $value, $case_sen);

$name is the name of the constant.
$value is the value of the constant.
$case_sen is an optional boolean parameter indicating whether to be case-sensitive (true) or not (false).

define("pi",3.14,true); echopi; //Outputs 3.14

  1. You can use the defined() function to check for the existence of a constant. This function returns true if the constant is declared. Example:
//Declare the constant pi define("pi",3.14,true); if (defined("pi")==true) echo "The constant pi is declared!"; //The script will output "Constant pi declared!"

Differences Between Constants and Variables in PHP for Dummies

  1. Constants do not have a dollar sign prefix ($).
  2. Constants can only be defined using the define() function, not by assigning a value.
  3. Constants can be defined and accessed anywhere without regard to scope.
  4. Constants cannot be defined or invalidated after the initial declaration.
  5. Constants can only have scalar values.

PHP programming for dummies. Part 1 was last modified: March 3rd, 2016 by Admin

The Internet in the modern world occupies an increasingly strong position. About 15 years ago, access to the network required expensive equipment and a lot of money to pay bills. Now anyone who has at least a mobile phone can get on the Internet for a penny. More and more services and services are moving to electronic form. From a means of communication and information exchange, the Internet is turning into a convenient tool for doing business and making money.

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

This electronic textbook is intended for those who simply surf the Web is not enough. For those who want to learn how to create their own websites and be on the wave of the latest trends in programming and design.

General principles

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

The Internet network 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 host's IP address, 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 (Domain Name Resolution) servers on the Internet, which store lists of mapping 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 name of the page in the browser.

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

Obviously, all page rendering actions can be unambiguously 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 does not know anything about the current state of the client, and the client knows nothing about the current state of the server. When developing exchange algorithms, one must always keep this in mind and transmit the necessary data in a timely manner, describing the state or the 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. Back-end developers are less constrained in terms of funds, because most existing languages ​​allow you to create or describe HTML pages. The most widely used now are Java, Perl, PHP, Python, Ruby, C# and VB.NET. Each of them has its own strengths and weaknesses, so the developer must make a choice based on the tasks facing him.

Why PHP?

There are a large number of languages ​​that can be used when creating websites. Some languages ​​have been around for a long time and are successfully used (or no longer used). Some languages ​​are still very young and have not yet received wide distribution. Recently, PHP has become one of the leaders in popularity, for several reasons:

  1. Simplicity. The language is very easy to understand, especially for novice programmers.
  2. Development speed. Due to its simplicity and intuitiveness, PHP allows you to create quite complex sites very quickly.
  3. Availability of libraries There are a huge number of ready-made examples and class libraries. Hundreds of libraries have been created and tested, greatly simplifying the life of a developer.
  4. Support Almost every server on the internet supports PHP
  5. Safety PHP allows you to create truly secure sites with built-in support for data encryption at rest and in transit.

However, PHP pays for its benefits with some limitations. For example, using PHP to access system functions is very inconvenient compared to Perl or Python (which is why many sysadmins love Perl so much). There are a few more limitations that we'll talk about in the relevant sections.

Holding on to "number one", PHP is one of the most popular languages ​​among developers. Although many prefer other languages. For example, many people prefer to work in ASP.NET. However, due to the great popularity of Wordpress, more and more developers decide to expand their horizons and learn another language.

And so, it happened that I became one of these people. My clients have been asking more and more about using Wordpress and so learning PHP has become a necessity. And I'm not alone in this direction. For those who find themselves in the same boat as me, why not spend some time and learn a little with me?

My plans

In a number of the next articles, which I will post on Wednesdays, I am going to post materials for our training. If you've been meaning to explore this subject but haven't started yet, now is the time! On the other hand, for those who are already PHP ninjas, I kindly ask you to stay with us and share your tips with us. If you have benefited from any of the tutorials on this site, please take the time to provide feedback in the comments section. This will be our general resource for everything in PHP. Every Wednesday, I'll be posting a tutorial article, as well as links to helpful resources where you'll find more in-depth coverage of the topics covered. The bottom line here is that I'm a newbie just like you. But we can motivate each other to learn faster and more effectively.

Why would you want to learn from a newbie? Try not to think that I am teaching you. Think of these articles as a community where everyone helps each other. I will learn as much from you as you do from me.

What is PHP?

PHP stands for Hypertext Preprocessor. While other languages ​​such as Javascript run on the client side, your PHP code will run on the server side. It works seamlessly with our HTML. Also, your PHP can be embedded in your HTML and vice versa. It's important to remember that no matter how complex your PHP is, it will end up being output as plain HTML.

Why should I use PHP?

HTML is 100% static. Using PHP code, we can make dynamic websites that can change depending on the conditions. With a community that is second to none, this open source language has proven itself over the years as one of the best choices for dynamic web applications.

Absolutely. I was pleasantly surprised at the beginning of the training. If you have a basic knowledge of ASP.NET, Perl, Javascript, or C#, you will quickly get comfortable with the syntax of the language.

What do I need to get started?

First, you need to install the following components on your computer.

  • Apache
  • MySQL
  • Browser
  • Text editor or code editor

WAMP, MAMP

Yes, I have to apologize, but you need to learn a few abbreviations. WAMP stands for "Windows-Apache-MySQL-PHP". This is an open source project that will allow us to download everything we need to get started. If you are a Windows user, then I recommend you go to WampServer.com. And if you use a Mac (MAMP), then you will need to go to Mamp.info

Video lessons

Our first stop is . Perhaps more than any other resource, Linda.com gave me a lot of valuable knowledge for which I will always be grateful. For the price of a couple of pizzas, you'll get access to a video database that goes into detail on everything from ASP to SEO - and every other acronym in between. If a client asks me to work with some software with which I am not familiar, the first place I turn to is Linda.com. If you're still in doubt, why don't you google "Lynda.com free trial". I assure you, you will definitely find something for yourself. Just make sure you're more than satisfied with what they have to offer and then sign up.

After you create a subscription for yourself there, or sign up for a free trial period, go to the site, and in the drop-down menu for Items, scroll down to PHP. For this tutorial, we will focus on the "PHP with MySQL Essential Training" video. Try to watch the first three lessons this week. This will prepare you for our lessons next week.

Basics

To contact the server we are working with using PHP, you need to use the following syntax when adding PHP code to your HTML document:

We start and end each php block with "" respectively. Look at your code and paste the following into it:

Please note that in the second example, we wrote everything in one line. Remember that PHP doesn't care about whitespace. Here we are talking to the server with the “echo” command so that it prints the phrase “This is PHP in action” to the screen. Each command in our code must end with a semicolon at the end. While HTML may forgive you if you accidentally forget a closing brace, PHP will not forgive you. If you do not use these syntax rules correctly, you will receive an error message. In this case, when we only have one declaration, we might get away with it and skip the semicolon. But from the very beginning it is necessary to learn to write the correct code.

Declaring Variables

Declaring variables is quite simple. Instead of using "var" (as in C# or Javascript), or "dim" (VB), we can declare a variable using the $ symbol. For example, suppose I want to assign the previous line to a variable named "myVariable". I can write...

As a result of this example, we will get the same result as before. However, in this case, we assigned a string to the variable, and printed out the variable. Now, let's see what happens if I want to concatenate (concatenate) a variable and a string?

Using this notation, we can combine variables and/or strings.

Inserting Comments in Your Code

If you're familiar with CSS and Javascript, you'll see that commenting in PHP is the same.

Combining HTML with Our PHP

As I said, you must remember that php and html can work together. Just because we're inside PHP code doesn't mean we can't insert a break or a strong tag with you.

This text is bold."; ?>

Creating Our First Function()

Creating a function in PHP is similar to declaring a function in Javascript. The basic rule of thumb is...

If we want to create a function that will output - "echos" 10 plus 5, we should write it like this..

We have created a simple function that prints "15". We have named the function addNumbers(). In this case, we do not use arguments. Let's see now how we can use them to make our function more flexible.

Now our code has become more versatile. When creating our addNumbers() function, we added two arguments $firstNumber and $secondNumber to it. And the function just outputs the sum of those two arguments. When calling the function, you need to substitute two numbers addNumbers(10, 5) into it. In a real situation, these could be values ​​from text fields.

I think that's enough for this week. If something is not clear to you, go back and re-read the article. Also, be sure to check out the resources suggested for you to help you get even better with PHP syntax. Please feel free to ask questions and give good advice in the comments. I will try to take your comments into account in the second part, which should appear next Wednesday. If you liked the article, please share a link to it in the social. networks!

Required Resources

Good day, dear readers of my blog. Somewhere I heard that every person in his life must go through writing poetry. The situation is changing and now every second person thinks about writing code and creating their own website. Many merge at the moment, others cannot decide on the engine in any way. If you finish reading this article and move on to learning 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 cherished three letters mean and you will learn about the best ways to not only learn, but also really understand PHP.

What is PHP?

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

In simple and accessible terms, php is a programming language specifically designed to script a web application that runs on a web server. This is a fairly 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 on your own. Without anyone's help.

We study effectively

Many began to learn 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, a tutorial or a 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 a statement and executes it.

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

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

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

Books for learning

Let me tell you, I am not a fan of books. When it comes to internet technology. It's like explaining to a Masai man what wi-fi is. No drawings will help to understand everything normally. Nevertheless, I want to provide you with a small list of php books for dummies that are listed among professionals.

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

PHP and MySQL. Web application development This is a great book for a beginner. First of all, the author will show 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 functions, creating your own engine and a number of other functions.


In general, nothing surprising is not it? But nevertheless, it is a real textbook with unique information that you will not find anywhere else. This is the fifth edition, so there will be no outdated information. The book was released in 2015. In order to start to get acquainted with the code yourself - that's it.

HTML, JavaScript, PHP and MySQL. Webmaster's Gentleman's Set - This is a more detailed tutorial on learning php. It touches on several other useful ones, without which the full creation of web applications is impossible.

Easy to read, suitable for self-study and student learning. The author covers such topics as: PHP basics, dynamic page generation with CSS (cascading style sheet), database administration, creating dynamic pages with JavaScript.


Build dynamic websites with PHP, MySQL, JavaScript, CSS and HTML5 - I would recommend this book to more advanced readers who already have basic HTML layout skills. 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 the book of Kevin Jank completes our review, in which the author makes a strong bias towards creating web applications with a database.


The book is very easy to read and is perfect for self-study.

YouTube video

From my own experience, I will say that learning php from YouTube videos is quite difficult. Even though they seem simple. Unlike the Photoshop tutorials that 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 the code yourself. Why, if the author has already done everything for you: typed, launched, showed with a specific example how everything works? As a result, remembering something is almost impossible.

Tutorial

In my opinion, this is the perfect learning experience. It's great to have an expert with you.

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

You will be given a task and will see how well you do it.

I can recommend you course on netology . This training center is valued among professionals, and in just two months you can learn everything you need. Sets in the group occur constantly.

Don't worry if you don't understand something. That's what the course is designed for you to learn. This is a real step-by-step guide for beginners. Don't believe? Download the full course program from the official website and you will see for yourself.


If you dream of learning how to create sites without, on your own and in php, then this is the best option for you.