How can the PHP substr function be used effectively in string manipulation tasks?
The PHP substr function can be used effectively in string manipulation tasks by allowing you to extract a portion of a string based on a specified start position and length. This can be useful for tasks such as truncating text, extracting specific parts of a string, or manipulating substrings within a larger string.
// Example of using substr to extract a portion of a string
$string = "Hello, World!";
$substring = substr($string, 0, 5); // Extracts "Hello" from the original string
echo $substring;