PHP | strings are a finite sequence of characters that consists of numbers, letters, special characters, and arithmetic values.
It is a sequence of characters containing numbers, letters, special characters, etc. It can be specified by a single quote, double-quote, or doc syntax.
There are three ways to specify PHP strings.These are:
single quoted:
like 'Learn PHP'double quoted:
like "Learn PHP OOP"heredoc syntax:
using heredoc syntax ("<<<")
PHP string can be created by enclosing text in a single quote character '
.
Source Code
<?php
$website='sudhakarinfotech is world one of the most popular learning platform for web development.';
echo $website;
?>
To insert a single quote inside the single quote string, just escape that character with a backslash. '
$string = 'Learn sudhakarinfotech's PHP tip and tricks';
Source Code
$stringText = 'Learn sudhakarinfotech's PHP new tip and tricks';
If you like to put '
inside the single-quoted string then Use to escape the character.
Source Code
$str = 'Learn web development tricks:';
Please keep in mind that the variable inside the single quote is not parsed by the PHP parser. Let us understand it with the help of an example.
Source Code
<?php
$learningResources ="sudhakarinfotech";
$learnFrontEnd = "Javascript";
$learnWebsite = "Learn web development: $learningResources";
$learnFrontEndDevelopment = 'Learning $learnFrontEnd is really easy.';
echo $learnWebsite."<br>";
//output Learn web development:
echo $learnFrontEndDevelopment;
//Learning $learnFrontEnd is really easy.
?>