How does the substr() function in PHP compare to similar functions in other programming languages?

The substr() function in PHP is used to extract a portion of a string. It is similar to functions like slice() in JavaScript, substring() in Java, and substr() in Python. These functions all allow you to extract a substring from a string based on the starting index and length of characters.

$string = "Hello, World!";
$substring = substr($string, 7, 5);
echo $substring; // Output: World