How can one efficiently extract a specific substring from a user input in PHP?

To efficiently extract a specific substring from a user input in PHP, you can use the `strpos()` function to find the position of the substring within the input, and then use `substr()` function to extract the desired substring based on the position and length. This approach allows you to easily extract the substring without needing to manually parse the input.

$userInput = "Hello, World!";
$substring = "World";

$pos = strpos($userInput, $substring);

if ($pos !== false) {
    $extractedString = substr($userInput, $pos, strlen($substring));
    echo $extractedString;
} else {
    echo "Substring not found in user input.";
}