What is the PHP function used to extract a portion of a string?
To extract a portion of a string in PHP, you can use the `substr()` function. This function takes three parameters: the string you want to extract from, the starting position of the extraction, and optionally the length of the extracted substring. Example:
$string = "Hello, World!";
$extracted = substr($string, 7, 5); // Extracts "World" starting from position 7
echo $extracted; // Output: World
Related Questions
- What is the correct syntax for setting a cookie to null or deleting it in PHP?
- How can one optimize the code for checking if a value exists in a database in PHP to make it more concise and efficient?
- How can PHP developers implement a more robust and scalable approach to user content moderation, beyond simple keyword filtering, to ensure a safer online environment?