phpsyntaxpreg-matcheregi

Replace eregi() with preg_match() syntax error


I have lines of php code that I need to change

while (eregi("([-]?)\"([^\"]+)\"", $a, $regs)) { 

to

while (preg_match("([-]?)\"([^\"]+)\"", $a, $regs)) {

and

if (strlen($word) < $min_word_length || (!eregi($pattern, remove_accents($word))) || ($common[$word] == 1)) {

to

if (strlen($word) < $min_word_length || (!preg_match($pattern, remove_accents($word))) || ($common[$word] == 1)) {

I tried all possible(I can) combinations, I searched on google and here also but can't figure it out.


Solution

  • you did not use the delimiters.... you can see the manual php.net/manual/en/regexp.reference.delimiters.php.

    try this "/([-]?)\"([^\"]+)\"/" (i'm only adding the "/" at the beginning and the end of the string "/$pattern/" )

    if (strlen($word) < $min_word_length || (!preg_match("/$pattern/", remove_accents($word))) || ($common[$word] == 1)) {