PHP String
In this chapter you will learn:
Description
A string variable is created using quotation.
Syntax
In PHP we have two syntax to define strings
$myString = 'string value';
or
$myString = "string value";
The first form uses the single quotation and the second form uses the double quotation.
Example
The following code creates a string in PHP.
<?PHP
$myString = 'hello from java2s.com';
print($myString);
?>
The code above generates the following result.
In this example, the string literal is enclosed in single quotation marks ('
).
You can also use double quotation marks ("
), as follows:
<?PHP
$myString = "hello from java2s.com";
print($myString);
?>
The code above generates the following result.
Multline strings
To specify multline strings in PHP, insert newlines into the string literal between the quotation marks:
<?PHP/* jav a 2 s . c o m*/
$myString = "
demo
from
java2s.com
";
echo $myString;
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter: