PHP - Concatenate Strings

0
3Кб

String Concatenation

To concatenate, or combine, two strings you can use the . operator:

ExampleGet your own PHP Server

$x = "Hello";
$y = "World";
$z = $x . $y;
echo $z;
Try it Yourself »

The result of the example above is HelloWorld, without a space between the two words.

You can add a space character like this:

Example

$x = "Hello";
$y = "World";
$z = $x . " " . $y;
echo $z;
Try it Yourself »

An easier and better way is by using the power of double quotes.

By surrounding the two variables in double quotes with a white space between them, the white space will also be present in the result:

Example

$x = "Hello";
$y = "World";
$z = "$x $y";
echo $z;
Try it Yourself »

Complete PHP String Reference

For a complete reference of all string functions, go to our complete PHP String Reference.

 
 

 

 

Поиск
Категории
Больше
Другое
PHP Create Arrays
Create Array You can create arrays by using the array() function: ExampleGet your...
От PHP Tutorial 2024-05-17 08:01:55 0 3Кб
Другое
تطورات التعلم الآلي وتأثيرها على مستقبل العمل
مقدمة: في ظل التطورات السريعة للتكنولوجيا والابتكار، أصبح التعلم الآلي...
От MOHAMED ATTALLAH 2024-05-14 13:56:58 0 3Кб
Другое
PHP Update Array Items
Update Array Item To update an existing array item, you can refer to the index number for...
От PHP Tutorial 2024-05-17 08:02:49 0 3Кб
Другое
PHP Magic Constants
PHP Predefined Constants PHP has nine predefined constants that change value depending on where...
От PHP Tutorial 2024-05-17 07:40:16 0 2Кб
Другое
PHP Multidimensional Arrays
In the previous pages, we have described arrays that are a single list of key/value pairs....
От PHP Tutorial 2024-05-17 08:07:20 0 3Кб