A string is a sequence of characters enclosed in single ('') or double ("") quotes. Strings are used to store and manipulate text in PHP.
'
)
<?php
$text = 'Hello, PHP!';
echo $text;
?>
✔ Outputs: Hello, PHP!
Single quotes treat the content as plain text and do not process variables inside them.
✅ Using Double Quotes ("
)
<?php
$name = "Alice";
echo "Hello, $name!";
?>
✔ Outputs: Hello, Alice!
Double quotes allow variable interpolation, meaning PHP replaces variables with their values.
.
Operator)The .
(dot) operator joins two or more strings together.
<?php
$first = "Hello";
$second = "World!";
echo $first . " " . $second;
?>
✔ Outputs: Hello World!
strlen()
)The strlen()
function returns the length of a string.
<?php
echo strlen("Hello, PHP!");
?>
✔ Outputs: 12
str_word_count()
)<?php
echo str_word_count("Learn PHP with ease!");
?>
✔ Outputs: 4 (counts the words)
strrev()
)