Are there any potential pitfalls to be aware of when using the substr() function in PHP in combination with strpos() for string manipulation?
When using the substr() function in combination with strpos() for string manipulation in PHP, it's important to be aware that strpos() returns false if the substring is not found in the string. This can lead to unexpected results when passing the result directly to substr(). To avoid this pitfall, you should explicitly check for false before using the result of strpos() in substr().
$string = "Hello, World!";
$substring = "World";
$pos = strpos($string, $substring);
if ($pos !== false) {
$result = substr($string, $pos);
echo $result;
} else {
echo "Substring not found in string.";
}