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

user5247236 picture user5247236 · Sep 13, 2016 · Viewed 58.5k times · Source

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?

Answer

Hyder B. picture Hyder B. · Sep 13, 2016

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']));