PHP Strings
A string is a sequence of characters used to represent text.
What is it?
A string is a sequence of characters used to represent text.
Why do we use it?
Strings are required for names, messages, addresses, emails and HTML content.
How does it work?
PHP stores characters between quotes and provides many functions for manipulating them.
Syntax
$text = "Hello PHP";
Example
<?php $name = "AIFA Infotech"; echo strlen($name) . "<br>"; echo strtoupper($name) . "<br>"; echo strtolower($name); ?>
Example Explained
More Examples
<?php $text = "Hello World"; echo str_replace("World", "PHP", $text); ?>
⚠️ Important Rules
PHP provides many string functions such as strlen, strtoupper, strtolower, trim and str_replace.
❌ Common Mistakes
Incorrect quotation marks or confusing concatenation with addition.
🌍 Real-World Use
String processing is common in forms, search, authentication and database applications.
📝 Practice Exercise
Create a program that formats a student's full name.
💻 Try It Yourself
Write and run this PHP lesson inside the AIFA Coding Lab.