Substring and Padding Functions
Extract and format string segments with substr, str_pad, and wordwrap.
Extracting Parts of Strings
PHP has powerful functions to extract, truncate, and pad strings. These are essential for formatting output and processing text data.
substr()
Extract a portion of a string by start position and optional length:
<?php
$str = 'Hello, World!';
echo substr($str, 7); // World!
echo substr($str, 7, 5); // World
echo substr($str, -6); // World!
echo substr($str, -6, 5); // WorldAll lessons in this course
- String Basics and Concatenation
- Searching and Replacing in Strings
- Substring and Padding Functions
- Splitting and Joining Strings