Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7

64.7k Views Asked by At

below code is giving me the fatal error in php 7

    $jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));

is there any way to make it compatible with php 7?

2

There are 2 best solutions below

1
Hyder B. On BEST ANSWER

Switch to preg_replaceDocs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replaceDocs).

Your above code should be this way:

$jquery_click_hook = preg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
0
Keyur Mistry On

ereg_replace function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0. So you must have to use preg_replace() function instead of ereg_replace()