Strings in PHP
Strings
They are sequences of characters, like "PHP supports string operations". Following are valid examples of string
$string_1 = "This is a string in double quotes"; $string_2 = "This is a somewhat longer, singly quoted string"; $string_39 = "This string has thirty-nine characters"; $string_0 = ""; // a string with zero characters
Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.
<? $variable = "name"; $literally = 'My $variable will not print!\\n'; print($literally); $literally = "My $variable will print!\\n"; print($literally); ?>
This will produce following result:
My $variable will not print!\n My name will print
There are no artificial limits on string length - within the bounds of available memory, you ought to be able to make arbitrarily long strings.
Strings that are delimited by double quotes (as in "this") are preprocessed in both the following two ways by PHP:
- Certain character sequences beginning with backslash (\) are replaced with special characters
- Variable names (starting with $) are replaced with string representations of their values.
Strings in PHP
Reviewed by Rajat Jha
on
19:49:00
Rating:
No comments: