What is the function `substr()` used for in PHP?
The `substr()` function in PHP is used to extract a portion of a string. It takes in three parameters: the string to extract from, the starting position of the extraction, and the length of the extracted portion. This function is commonly used when you need to work with substrings within a larger string.
// Extract a portion of a string starting from position 0 and with a length of 5 characters
$originalString = "Hello, World!";
$extractedString = substr($originalString, 0, 5);
echo $extractedString; // Output: Hello
Related questions
-
PHP automation database
-
PHP array JavaScript JSON
-
password verification PHP password_hash