Skip to content
PHP Logo

How can the deprecated function split() be replaced in PHP 7.X to avoid fatal errors?

The deprecated function split() in PHP 7.X can be replaced with the preg_split() function to avoid fatal errors. preg_split() is a more powerful alternative that uses regular expressions to split a string. By using preg_split(), you can continue to split strings without encountering any issues related to the deprecated split() function.

php
// Using preg_split() to replace the deprecated split() function
$string = "Hello,World";
$parts = preg_split('/,/', $string);
print_r($parts);