Google News
logo
PHP Program to string
In PHP, a string is a sequence of characters that is enclosed in single quotes (`'`) or double quotes (`"`).

Here's an example of a string in PHP :
Program :
<?php
$name = "John";
echo "Hello, $name!";
?>

In this example, the string "Hello, $name!" contains a variable (`$name`) which is interpolated into the string. When the code is executed, the output will be:

Output :
Hello, John!
You can also use single quotes to create a string in PHP :
Program :
<?php
$name = 'Jane';
echo 'Hello, ' . $name . '!';
?>

In this example, the string "Hello, " is concatenated with the variable `$name` and the string "!" using the `.` operator. The output will be :

Output :
Hello, Jane!
You can also use escape sequences to include special characters in a string, such as a newline (`\n`) or a tab (`\t`):
<?php
echo "First line.\nSecond line.\nThird line.";
?>​
Output :
First line.
Second line.
Third line.​