PHP - Slicing Strings
In PHP, slicing strings means extracting a portion (or substring) of a string. This is typically done using the substr()
or mb_substr()
functions. Here's how you can use them:
1. Using substr()
Syntax:
-
$start
: Starting position (0-based). Negative values count from the end. -
$length
(optional): Number of characters to extract.
Examples:
2. Using mb_substr()
for multibyte strings
Use this if your string contains multibyte characters (e.g., UTF-8, Japanese, emojis).