Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Strings | Variables and Data Types
Introduction to PHP
course content

Зміст курсу

Introduction to PHP

Introduction to PHP

1. First Acquaintance
2. Variables and Data Types
3. Conditional Statements
4. Arrays
5. Loops

bookStrings

Strings are used to represent textual information and can be defined within single ' ' or double " " quotes.

php

main

copy
1234
<?php $name = "John"; $message = 'Hello, World!'; ?>

Strings can contain any characters, including letters, digits, and special symbols.

String Concatenation


Concatenation in PHP is used to join strings together into one string. The concatenation operator . (dot) is used for this purpose:

php

main

copy
1234567
<?php $firstName = "John"; $lastName = "Doe"; $fullName = $firstName . " " . $lastName; // `$fullName` will be `"John Doe"` echo $fullName; ?>

The code above defines two variables, $firstName and $lastName, with values "John" and "Doe" respectively. It concatenates them into $fullName using the dot operator and then outputs the full name "John Doe" using echo.

Using Single and Double Quotes


You can use both '(single) and "(double quotes) to define strings. They have some differences in how they handle variables and special characters.

Double quotes allow variables to be directly used within the string and support escaping special characters:

php

main

copy
123456
<?php $name = "John"; $message = "Hello, $name!"; echo $message; ?>

Single quotes treat everything inside them as literal text, ignoring variables and special characters:

php

main

copy
123456
<?php $name = "John"; $message = 'Hello, $name!'; echo $message; ?>
Завдання
test

Swipe to show code editor

  1. Assign any name to the variable $name.

  2. Concatenate the strings using the . operator so that running the code outputs the greeting "Hello, SomeName!".

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 3
toggle bottom row

bookStrings

Strings are used to represent textual information and can be defined within single ' ' or double " " quotes.

php

main

copy
1234
<?php $name = "John"; $message = 'Hello, World!'; ?>

Strings can contain any characters, including letters, digits, and special symbols.

String Concatenation


Concatenation in PHP is used to join strings together into one string. The concatenation operator . (dot) is used for this purpose:

php

main

copy
1234567
<?php $firstName = "John"; $lastName = "Doe"; $fullName = $firstName . " " . $lastName; // `$fullName` will be `"John Doe"` echo $fullName; ?>

The code above defines two variables, $firstName and $lastName, with values "John" and "Doe" respectively. It concatenates them into $fullName using the dot operator and then outputs the full name "John Doe" using echo.

Using Single and Double Quotes


You can use both '(single) and "(double quotes) to define strings. They have some differences in how they handle variables and special characters.

Double quotes allow variables to be directly used within the string and support escaping special characters:

php

main

copy
123456
<?php $name = "John"; $message = "Hello, $name!"; echo $message; ?>

Single quotes treat everything inside them as literal text, ignoring variables and special characters:

php

main

copy
123456
<?php $name = "John"; $message = 'Hello, $name!'; echo $message; ?>
Завдання
test

Swipe to show code editor

  1. Assign any name to the variable $name.

  2. Concatenate the strings using the . operator so that running the code outputs the greeting "Hello, SomeName!".

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 3
toggle bottom row

bookStrings

Strings are used to represent textual information and can be defined within single ' ' or double " " quotes.

php

main

copy
1234
<?php $name = "John"; $message = 'Hello, World!'; ?>

Strings can contain any characters, including letters, digits, and special symbols.

String Concatenation


Concatenation in PHP is used to join strings together into one string. The concatenation operator . (dot) is used for this purpose:

php

main

copy
1234567
<?php $firstName = "John"; $lastName = "Doe"; $fullName = $firstName . " " . $lastName; // `$fullName` will be `"John Doe"` echo $fullName; ?>

The code above defines two variables, $firstName and $lastName, with values "John" and "Doe" respectively. It concatenates them into $fullName using the dot operator and then outputs the full name "John Doe" using echo.

Using Single and Double Quotes


You can use both '(single) and "(double quotes) to define strings. They have some differences in how they handle variables and special characters.

Double quotes allow variables to be directly used within the string and support escaping special characters:

php

main

copy
123456
<?php $name = "John"; $message = "Hello, $name!"; echo $message; ?>

Single quotes treat everything inside them as literal text, ignoring variables and special characters:

php

main

copy
123456
<?php $name = "John"; $message = 'Hello, $name!'; echo $message; ?>
Завдання
test

Swipe to show code editor

  1. Assign any name to the variable $name.

  2. Concatenate the strings using the . operator so that running the code outputs the greeting "Hello, SomeName!".

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Strings are used to represent textual information and can be defined within single ' ' or double " " quotes.

php

main

copy
1234
<?php $name = "John"; $message = 'Hello, World!'; ?>

Strings can contain any characters, including letters, digits, and special symbols.

String Concatenation


Concatenation in PHP is used to join strings together into one string. The concatenation operator . (dot) is used for this purpose:

php

main

copy
1234567
<?php $firstName = "John"; $lastName = "Doe"; $fullName = $firstName . " " . $lastName; // `$fullName` will be `"John Doe"` echo $fullName; ?>

The code above defines two variables, $firstName and $lastName, with values "John" and "Doe" respectively. It concatenates them into $fullName using the dot operator and then outputs the full name "John Doe" using echo.

Using Single and Double Quotes


You can use both '(single) and "(double quotes) to define strings. They have some differences in how they handle variables and special characters.

Double quotes allow variables to be directly used within the string and support escaping special characters:

php

main

copy
123456
<?php $name = "John"; $message = "Hello, $name!"; echo $message; ?>

Single quotes treat everything inside them as literal text, ignoring variables and special characters:

php

main

copy
123456
<?php $name = "John"; $message = 'Hello, $name!'; echo $message; ?>
Завдання
test

Swipe to show code editor

  1. Assign any name to the variable $name.

  2. Concatenate the strings using the . operator so that running the code outputs the greeting "Hello, SomeName!".

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 3
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt