-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #360 from hexlet-basics/new
new structure
- Loading branch information
Showing
675 changed files
with
12,949 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Copy the exact code from the instructions into the editor and run it by clicking «Run». | ||
|
||
```php | ||
<?php | ||
|
||
print_r('Hello, World!'); | ||
``` | ||
|
||
Note: If you write `heLLo, woRld!` instead of `Hello, World!`, it will be considered different text because upper and lower case letters are different characters. _Case is important!_ This rule affects almost everything in coding, so make sure you get used to paying close attention to the case at all times. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
As is our tradition, we'll begin by writing the 'Hello, World!' program. The program will print the following text: | ||
|
||
<pre class='hexlet-basics-output'> | ||
Hello, World! | ||
</pre> | ||
|
||
Output to the screen is done with a special command `echo`, followed by a single or double-quoted string to be output. Be sure to put a semicolon at the end. | ||
|
||
```php | ||
<?php | ||
|
||
echo 'Hello, World!'; // => Hello, World! | ||
``` | ||
|
||
https://replit.com/@hexlet/php-basics-hello-world-echo | ||
|
||
There are other ways to display a string on the screen. For example, you can use the function (a concept we will get to know later) `print_r()`. In this case, the string is entered in parentheses immediately after the function name. You also need to put `;` at the end. | ||
|
||
```php | ||
<?php | ||
|
||
print_r('Hello, World!'); | ||
``` | ||
|
||
https://replit.com/@hexlet/php-basics-hello-world-printr | ||
|
||
In simple situations, there's no difference between these constructions. You can use either one method of output or the other. In more complex cases, where you want to display not just numbers or strings, but, for example, arrays, `echo` won't be able to do this, but `print_r()` will display everything. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: Hello, World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Escribe en el editor el código del ejercicio carácter por carácter y luego haz clic en "Verificar". | ||
|
||
```php | ||
<?php | ||
|
||
print_r('Hello, World!'); | ||
``` | ||
|
||
¡Atención! Si escribes `heLLo, woRld!` en lugar de `Hello, World!`, se considerará un texto diferente, ya que las mayúsculas y minúsculas son caracteres distintos. El tamaño de las letras se llama _mayúsculas_ y _minúsculas_, y se dice: ¡_las mayúsculas importan_! Esto se aplica a casi todo el código, así que acostúmbrate a prestar siempre atención a las mayúsculas y minúsculas. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
En esta lección vamos a escribir nuestro primer programa. Aprenderemos qué comandos se necesitan y qué etiquetas se deben utilizar para que el programa que ejecuta el código lo interprete correctamente. También aprenderemos por qué son necesarios los comentarios en el código. | ||
|
||
## Cómo escribir un programa simple | ||
|
||
Hay dos formas de escribir un programa y mostrar el resultado en la pantalla: | ||
|
||
* Usando el comando `echo` | ||
* Usando la función `print_r()` | ||
|
||
Veamos cada una en detalle. | ||
|
||
### Escribir un programa usando `echo` | ||
|
||
Vamos a escribir un programa que muestre "¡Hola, Mundo!" en la pantalla: | ||
|
||
```php | ||
<?php | ||
|
||
echo '¡Hola, Mundo!'; | ||
// => ¡Hola, Mundo! | ||
``` | ||
|
||
https://replit.com/@hexlet/php-basics-hello-world-echo | ||
|
||
La salida en la pantalla se realiza utilizando el comando especial `echo`. Después de él, se especifica la cadena a mostrar entre comillas simples. Al final, es importante colocar un punto y coma. | ||
|
||
Para mayor comodidad, mostraremos el resultado de la ejecución del código de esta manera: `=> RESULTADO`. | ||
|
||
### Escribir un programa usando `print_r()` | ||
|
||
Otra forma de mostrar una cadena en la pantalla es utilizando la función `print_r()`: | ||
|
||
```php | ||
<?php | ||
|
||
print_r('¡Hola, Mundo!'); | ||
// => ¡Hola, Mundo! | ||
``` | ||
|
||
https://replit.com/@hexlet/php-basics-hello-world-printr | ||
|
||
En este caso, la cadena se especifica entre paréntesis justo después del nombre de la función. Al final, también es necesario colocar un punto y coma. | ||
|
||
En situaciones simples, no hay diferencia entre estas dos construcciones. Puedes usar cualquier método. Sin embargo, cuando necesitas mostrar en la pantalla algo más que números o cadenas, por ejemplo, matrices, `echo` no podrá hacerlo, pero `print_r()` sí. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: ¡Hola, Mundo! | ||
tips: | ||
- > | ||
[Un poco sobre 'Hello, | ||
World!'](https://codica.la/blog/mi-gente-me-entiende-la-historia-de-la-frase-hello-world-y-sus-analogos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Наберите в редакторе код из задания символ в символ и нажмите «Проверить». | ||
|
||
```php | ||
<?php | ||
|
||
print_r('Hello, World!'); | ||
``` | ||
|
||
Внимание: если вы напишете `heLLo, woRld!` вместо `Hello, World!`, то это будет считаться другим текстом, потому что заглавные и строчные буквы — разные символы. Размер буквы называют _регистром_ и говорят: _регистр — важен!_ Это касается почти всего в коде, поэтому привыкайте всегда обращать внимание на регистр. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
В этом уроке мы сразу напишем первую программу. Мы узнаем, какие команды понадобятся для этого и какие теги нужно использовать, чтобы программа, которая выполняет код, восприняла его. Также узнаем, зачем в коде нужны комментарии. | ||
|
||
## Как написать простую программу | ||
|
||
Чтобы написать программу и вывести результат на экран, используют два способа: | ||
|
||
* Через команду `echo` | ||
* Через команду `print_r()` | ||
|
||
Разберем каждую подробнее. | ||
|
||
### Пишем программу через `echo` | ||
|
||
Напишем программу «Hello, World!». Она будет выводить на экран текст: | ||
|
||
```php | ||
<?php | ||
|
||
echo 'Hello, World!'; | ||
// => Hello, World! | ||
``` | ||
|
||
https://replit.com/@hexlet/php-basics-hello-world-echo | ||
|
||
Вывод на экран выполняется с помощью специальной команды `echo`. После нее в одиночных кавычках указывается строка для вывода. В конце обязательно ставим точку с запятой. | ||
|
||
Для удобства мы будем показывать результат запуска строк кода так: `=> РЕЗУЛЬТАТ`. | ||
|
||
### Пишем программу через `print_r()` | ||
|
||
Другой способ вывести строку на экран — функция `print_r()`: | ||
|
||
```php | ||
<?php | ||
|
||
print_r('Hello, World!'); | ||
// => Hello, World! | ||
``` | ||
|
||
https://replit.com/@hexlet/php-basics-hello-world-printr | ||
|
||
В этом случае строка указывается в скобках сразу после имени функции. В конце также нужно ставить `;`. | ||
|
||
В простых ситуациях между этими конструкциями нет разницы. Можно использовать любой способ. А там, где на экран нужно выводить не просто числа или строки, а, например, массивы, `echo` не сможет этого сделать, а `print_r()` все выведет. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: Привет, Мир! | ||
tips: | ||
- > | ||
[Немного о 'Hello, | ||
World!'](https://ru.hexlet.io/blog/posts/moy-chelovek-menya-ponimaet-istoriya-frazy-hello-world-i-ee-analogov) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Type the code from the example, and put the `<?php` tag at the beginning: | ||
|
||
```php | ||
<?php | ||
|
||
print_r('King in the North!'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PHP is probably the only language in which you can't start writing code right away. Such code will be perceived by the interpreter (the program executing the code) as plain text. Any PHP code should be wrapped in a `<?php ?>` construct. | ||
|
||
`<?php` is the opening tag and `?>` is the closing tag. PHP allows you to omit the closing part `?>`. And the PSR-12 code manual doesn't let you include it at all. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: Tags | ||
tips: | ||
- '[Basic Code Writing Standard (PSR-1)](https://www.php-fig.org/psr/psr-1/)' | ||
- '[Code Design Guide (PSR-12)](https://www.php-fig.org/psr/psr-12/)' | ||
definitions: | ||
- name: Interpreter | ||
description: a program that executes code written in a programming language. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Escriba el código del ejemplo y coloque la etiqueta `<?php` al principio: | ||
|
||
```php | ||
<?php | ||
|
||
print_r('King in the North!'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## ¿Por qué usar etiquetas? | ||
|
||
Para que el **intérprete** - el programa que ejecuta el código - lo interprete como código y no como texto normal, es necesario envolver cualquier código en PHP con la construcción `<?php ?>`. Esta es una característica de este lenguaje de programación. | ||
|
||
`<?php` es la etiqueta de apertura y `?>` es la etiqueta de cierre. PHP permite no especificar la parte de cierre `?>`. Y la guía de estilo de código PSR-12 prohíbe su especificación. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Etiquetas | ||
tips: | ||
- '[PSR-1: Estándar básico de codificación](https://www.php-fig.org/psr/psr-1/)' | ||
- >- | ||
[PSR-12: Guía de estilo de | ||
codificación](https://www.php-fig.org/psr/psr-12/) | ||
definitions: | ||
- name: Intérprete | ||
description: programa que ejecuta el código escrito en un lenguaje de programación. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Наберите код из примера, поставьте в начале тег `<?php`: | ||
|
||
```php | ||
<?php | ||
|
||
print_r('King in the North!'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Зачем использовать теги | ||
|
||
Чтобы **интерпретатор** — программа, которая выполняет код, — восприняла его не как обычный текст, любой код на PHP нужно оборачивать в конструкцию `<?php ?>`. Это особенность данного языка программирования. | ||
|
||
`<?php` — это открывающий тег, а `?>` — закрывающий тег. PHP позволяет не указывать закрывающую часть `?>`. А руководство по оформлению кода PSR-12 запрещает ее указывать. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Теги | ||
tips: | ||
- >- | ||
[Базовый стандарт написания кода | ||
(PSR-1)](https://www.php-fig.org/psr/psr-1/) | ||
- >- | ||
[Руководство по оформлению кода | ||
(PSR-12)](https://www.php-fig.org/psr/psr-12/) | ||
definitions: | ||
- name: Интерпретатор | ||
description: программа, выполняющая код, написанный на языке программирования. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Create a one-line comment with the text: `You know nothing, Jon Snow!`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
Almost every programming language allows you to add comments to your code. This is text that isn't part of the program and is needed for programmers to make notes. They help explain how the code works, what errors need to be corrected, or what not to forget to add later. | ||
|
||
Comments in PHP come in two flavors: | ||
|
||
## Single line comments | ||
|
||
_Single line comments start with `//`. Any text can go after these characters, the whole line will be left alone when the program is run. | ||
|
||
A comment can take up a whole line. Or you can create several comments if one line isn't enough: | ||
|
||
```php | ||
<?php | ||
|
||
// For Winterfell! | ||
// For Lanisters! | ||
``` | ||
|
||
Or it can go after code on the same line: | ||
|
||
```php | ||
<?php | ||
print_r('I am the King'); // For Lannisters! | ||
``` | ||
|
||
## Multi-line comments | ||
|
||
_Multiline comments_ start with `/*` and end with `*/`. Each line between them must begin with a `*`. | ||
|
||
```php | ||
<?php | ||
/* | ||
* The night is dark and | ||
* full of terrors. | ||
*/ | ||
print_r('I am the King'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Comments | ||
tips: [] | ||
definitions: | ||
- name: Comment | ||
description: > | ||
text in program code that doesn't affect functionality, and is added by | ||
programmers for themselves and their colleagues. | ||
`// single-line comment` | ||
``` | ||
/* | ||
* multiline comment | ||
* multiline comment | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Crea un comentario de una línea con el texto: `¡No sabes nada, Jon Snow!`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## ¿Para qué sirven los comentarios? | ||
|
||
Además del código en los archivos de código fuente, puede haber comentarios. Este texto no es parte del programa. Es útil para los programadores como notas. Con ellos se agregan explicaciones, por ejemplo, cómo funciona el código, qué errores corregir o qué agregar más tarde. | ||
|
||
Los comentarios en PHP pueden ser de dos tipos: | ||
|
||
* **Comentarios de una línea** - comienzan con `//`. Después de estos caracteres puede seguir cualquier texto, toda la línea no se analizará ni se ejecutará: | ||
|
||
```php | ||
<?php | ||
|
||
// ¡Por Winterfell! | ||
// ¡Por Lannisters! | ||
// El comentario puede estar en la línea después de algún código | ||
print_r('Soy el Rey'); // ¡Por Lannisters! | ||
``` | ||
|
||
* **Comentarios de varias líneas** - comienzan con `/*` y terminan en `*/`. Entre ellos, cada línea debe comenzar con el carácter `*`: | ||
|
||
```php | ||
<?php | ||
/* | ||
* La noche es oscura y | ||
* está llena de terrores. | ||
*/ | ||
print_r('Soy el Rey'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Comentarios | ||
tips: [] | ||
definitions: | ||
- name: Comentario | ||
description: > | ||
texto en el código del programa que no afecta la funcionalidad y se agrega | ||
por los programadores para ellos mismos y sus colegas. | ||
`// comentario de una línea` | ||
``` | ||
/* | ||
* comentario de varias líneas | ||
* comentario de varias líneas | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Создайте однострочный комментарий с текстом: `You know nothing, Jon Snow!`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## Зачем нужны комментарии | ||
|
||
Кроме кода в файлах с исходным кодом могут находиться комментарии. Этот текст не является частью программы. Он нужен программистам для пометок. С их помощью добавляют пояснения, например, как работает код, какие ошибки нужно поправить или не забыть что-то позже добавить. | ||
|
||
Комментарии в PHP бывают двух видов: | ||
|
||
* **Однострочные комментарии** — начинаются с `//`. После этих символов может следовать любой текст, вся строка не будет анализироваться и исполняться: | ||
|
||
```php | ||
<?php | ||
|
||
// For Winterfell! | ||
// For Lanisters! | ||
// Комментарий может находиться на строке после какого-нибудь кода | ||
print_r('I am the King'); // For Lannisters! | ||
``` | ||
|
||
* **Многострочные комментарии** — начинаются с `/*` и заканчиваются на `*/`. Между ними каждая строка должна начинаться с символа `*`: | ||
|
||
```php | ||
<?php | ||
/* | ||
* The night is dark and | ||
* full of terrors. | ||
*/ | ||
print_r('I am the King'); | ||
``` |
Oops, something went wrong.