PHP/String/String Concatenation — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:07, 26 мая 2010
Содержание
- 1 A period (.) character is used to combine two separate variables into a single string
- 2 A string and an integer value are added, and the result is an integer value.
- 3 Combining a string and a number
- 4 Concatenating strings together
- 5 Concatenation operator (".")
- 6 Joining and Disassembling Strings
A period (.) character is used to combine two separate variables into a single string
<?php
$string = "Thank you for buying ";
$newstring = $string . "my book!";
?>
A string and an integer value are added, and the result is an integer value.
<?php
$a="5";
$b= 7 + $a;
echo "7 + $a = $b";
?>
Combining a string and a number
<?php
$str = "This is an example of ". 3 ." in the middle of a string.";
echo $str;
?>
Concatenating strings together
<?php
$my_string = "Hello Max. My name is: ";
$newline = "<br />";
echo $my_string . "Paula" . $newline;
echo "Hi, I"m Max. Who are you? " . $my_string . $newline;
echo "Hi, I"m Max. Who are you? " . $my_string . "Paula";
?>
Concatenation operator (".")
<?
$a = "Hello ";
$b = $a . "World!"; // now $b contains "Hello World!"
$a = "Hello ";
$a .= "World!"; // now $a contains "Hello World!"
?>
Joining and Disassembling Strings
<?php
$string1 = "Hello";
$string2 = " World!";
$string3 = $string1 . $string2;
?>