0PricingLogin
PHP Academy · Lesson

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);   // World

All lessons in this course

  1. String Basics and Concatenation
  2. Searching and Replacing in Strings
  3. Substring and Padding Functions
  4. Splitting and Joining Strings
← Back to PHP Academy