12

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?

apokryfos
  • 38,771
  • 9
  • 70
  • 114
  • 1
    Possible duplicate of [How can I convert ereg expressions to preg in PHP?](https://stackoverflow.com/q/6270004/1255289) – miken32 Apr 20 '17 at 19:48

2 Answers2

26

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']));
Hyder B.
  • 10,900
  • 5
  • 51
  • 60
  • You should switch to mb_ereg_replace ; preg_replace has some issues with accented characters that I've not been able to resolve by changing locale, encoding etc. – Kohjah Breese Nov 29 '17 at 11:06
5

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()

Keyur Mistry
  • 926
  • 6
  • 18