Search code examples
phpphp-7ereg-replace

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


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?


Solution

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