Hello everyone, this tutorial is about understanding and using strings in PHP.
So we all know that the strings are the sequences of characters or it could be a sentence or a phase. or maybe a word.
“String in PHP”
Valid example of strings in PHP would be as follows:[php]$string = “This is a string.”;[/php]
If you can notice from the codes above. This string is inside the double quotes. And now we will be using a single quoted string.[php]$string = ‘This is a string.’;[/php]
All the statements from the codes above has the same output which is. “This is a string.”.
But singly quoted strings are the most treated literally, whereas double quoted strings replace variable with their values as well as specially interpreting certain character sequences. See the following codes:[php]<?php<?php $variable = “name”; $statement = ‘My $variable is Harley\\n’; print($statement); $statement = “My $variable is Harley\\n”;?>[/php]
My $variable is Harley\n
My name is Harley
There are no artificial limits on string lengths – within the bounds of available memory, you ought to be able to make arbitrarily long strings.
Strings that are in the double quotes, for example “statement” are prepossessed in both the following ways by PHP:
- The characters beginning with backslash (\) are replaced with special characters
- Variables for example “$statement” are replace with string representations of their values.
The escape-sequence replacements are:
- \n – replace by the newline character
- \r – replace by the carriage-return character
- \t – replace by the tab character
- \$ – replace by the dollar sign itself
- \” – replace by a single double-quote
- \\ – replace by a single backlash
if you have questions regarding these article entitled as “Understanding Strings in PHP“ feel free to ask us by commenting below or visit on our contact page. Thank you.