Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

PHP Strings

String Creation

$single = 'Single quoted';
$double = "Double quoted - $variable interpolated";

Common Functions

strlen($str); // String length
strpos($str, "find"); // Find position
substr($str, 0, 5); // Extract substring
str_replace("old", "new", $str); // Replace text
strtolower($str); // Convert to lowercase
strtoupper($str); // Convert to uppercase
trim($str); // Remove whitespace

Concatenation

Use . (dot operator):

$greeting = "Hello, " . $name . "!";