PHP language standards


Why should a web developer know standards

Standards are written and adopted by the W3C, a non-profit organization founded by Tim Berners-Lee. It consists of many working groups: they include representatives from browser companies, major universities, research institutes, and other organizations. Participants discuss with browser developers the design and implementation of the API, and then develop common standards.

The main benefit of knowing web standards is that you don’t have to learn new specifications. Developers are not afraid that the browser will come out with a spec that will break the old functions of their web application. If you do not know about the existence of a feature, then you can simply not use it and live in peace.

How to study standards and what to read

I started learning web development from books and CHM files. I downloaded them at school during computer science lessons, saved them to a USB flash drive, read the help at home and repeated the examples – and that’s how I learned to typeset. And I got acquainted with the standards when I gained experience and wanted to understand more deeply how the browser works with web pages.

All standards are written in English, so it will be difficult for a beginner who does not speak the language to learn them in the original. I advise you to pay attention to more accessible sources.

Blogs of devrels and IT evangelists. Read those who directly develop and adopt web standards. For example, Google developers often talk about the capabilities and features of the Chrome engine in their articles. There are always many detailed examples and illustrations, so they are pleasant and easy to read.

Among the CSS evangelists who write about CSS are the folks at Google: Adam Argyle (@argyleink), Yuna Kravetz (@Una), and Jake Archibald (@jaffathecake). A lot of useful and relevant materials can be found in the blog of Alexander Surma (Surma).

CSS grid video

Speech by Yuna Kravets at the European CSS Conf

Firefox also has a great developer blog. I advise you to subscribe to it if you want to be among the first to learn news about the browser and web standards in general.

Our index.html main page code will look like this:

<!DOCTYPE html>
<html lang="en">
<head>
<meracharset="UTF-8">
<title>Example</title>
</head>
<body>
<form action="handler.php" method="get">
<label>
Product
<input type="text" name="searchText">
</label>
<input type="submit" name="searchSubmit" value="Search">
</form>
</body>
</html>

We have a form with a text field and a button. The action attribute of the <form> tag points to the name and path of the script file that will process the entered data – in our case, this is the handler.php file. The method attribute indicates the method of data transfer – get; there is also a post method.

Let’s write the code for the handler.php script.

<?php
echo "<link rel='stylesheet' href='styles.css'>";
$fruits = array('Apples' => '30kg', 'Pears' => '50kg', 'Bananas' => '20kg');
$vegetables = array('Potatoes' = '100kg', 'Cucumbers' => '80kg', 'Tomatoes' => '50kg');
$berries = array('Cherry' => '20kg', 'Grapes' => '30kg', 'Raspberry' => '50kg');
$searchText = mb_strtolower($_GET['searchText'];
if(isset($_GET['searchSubmit'])){
if($searchText == 'fruit')
$products = $fruits;
elseif ($sesrchText == 'vegetables')
$products = $vegetables;
esleif ($sesrchText == 'berries')
$products = $berries;
echo '<table>
<head>
<td>Product</td>
<td>Number</td>
</thing>;
foreach ((array)$products as $key => $value) {
echo '<tr>
<td>'. $key .'</td>
<td>'. $value .'</td>
</tr>;
}
echo '<table>';
}
?>

Let’s analyze the code a bit:

 Lines 3–5 create three arrays that contain information about fruits, vegetables, and berries. In fact, this kind of data should be stored in the database and then pulled out of it. But as an example, we entered them manually in the code.

 Line 7 creates the $searchText variable, which contains the value entered in the text field. This value is taken from the $_GET super-global array, which is enclosed in square brackets with the name of the text field that we specified in the index.html file. This array is initialized when the form is submitted.

 Lines 9–15 first check to see if the submit button of the form, which has the name searchSubmit, has been clicked, then the value entered is checked, and depending on what kind of product the user has entered, the $products variable is set to the corresponding array previously created.

 Lines 17–28 display the array as a table on the screen. As you can see, PHP distinguishes HTML tags from ordinary strings and displays an HTML table in the browser window using the echo function.

 Line 22 loops through our products array with a special foreach loop statement.

To give the table a nice look, we will create a small styles.css file. It is included in the handler.php file in the second line of the code.

All is ready. Let’s start our web server and go to the address example in the address bar of the browser.

ENTER THE VALUE “FRUIT” IN THE FIELD AND PRESS THE SEARCH BUTTON.

The index.html main page will open.

As a result, the web server redirected us to the execution of the handler.php script, which, in turn, displayed a table of fruits on the screen. Pay attention to the address bar.

This is what our get request looks like.

After the question mark, the name of the parameter is indicated, in this case it is the name of the searchText field, and its entered value is indicated through the “=” sign. There can be several such “name = value” pairs, they must be separated by the “&” sign. It is not recommended to use this transfer method if you need to transfer a large amount of data or some sensitive data, such as login and password. In such cases, the post method is used.

With further study – for example, as part of the Skillbox PHP Developer course – you will definitely learn about such important things as PHP interaction with the database, building an object model, making asynchronous requests without reloading the page, and how the architecture is built highly loaded systems.

We emphasize once again that PHP is one of the most popular programming languages ​​at the moment. And suddenly you still have not decided whether to start learning PHP or not, you can be sure: – it will open up great opportunities for you. Whether you can use them is up to you.

Leave a Reply

Your email address will not be published.