Hi guys, I wrote:

<?php
    $WACnt=33;
    while($WACnt>=0)
    {
          require("Wordsarray.php");
          $enn=preg_replace("/".$normal[$WACnt]."/i",$tidied[$WACnt],$enn);
          $WACnt--;
    }
?>

The browser said:

Warning: Unknown modifier 'g' in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Compilation failed: nothing to repeat at offset 0 in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Unknown modifier 'b' in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Unknown modifier '-' in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Unknown modifier '-' in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Compilation failed: nothing to repeat at offset 0 in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Compilation failed: nothing to repeat at offset 0 in e:\appserv\www\chat\chat\Rooms_Func.php on line 223

Warning: Compilation failed: nothing to repeat at offset 0 in e:\appserv\www\chat\chat\Rooms_Func.php on line 223


________________________________________________
The error was in the $enn=preg_replace....

First of all, why do you require the "Wordsarray.php" file in each cycle of the while loop?
You should include (require) that file only once, before the loop and than do the while loop.
Than, about your error, I can only guess here, since you didn't provide the $normal and $tidied arrays: my guess is the problem is from one of the values in the $normal array and the opening and closing slashes ("/" and "/i") of your matching strings.
Let me expalin: if one of the values (strings) from $normal array contains a slash (/), let's say the string is "abcde/gb--", than your matching string in your expression becomes "/abcde/gb--/i"; now, the problem is that, in this case" your script thinks the second slash (the one before gb--) is the closing one (instead of the third one, the one before i), so it takes every character after that slash (gb--/i) as a pattern modifier, which, of course, is an error: "g", "b", "-" are not valid modifiers.
So, check to see if you have any slash "/" in the values of the $normal array, and if you have, you must escape them (put a backslash before any slash) before inserting them in the regular expression.
You can also use some other delimiter ("#" for instance), if it doesn't appear in your pattern strings.
From PHP manual: If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash.

You must also escape any special regexp character in your pattern strings (single and double quotes, the + and ? sign etc. Check the php manual!

Thanks guys I have sloved it.
The correct code:

<?php    $WACnt=33;    require("Wordsarray.php");    while($WACnt>=0)    {
          $enn=preg_replace("/".$normal[$WACnt]."/i",$tidie[$WACnt],$enn);          $WACnt--;    }?>

but the $normal array was containig values like:

'*b*'

and

'/b'

so I replaced each * with \*
and replaced each / with \/
So it is sloved now.

Edited 3 Years Ago by pyTony: fixed formatting

This question has already been answered. Start a new discussion instead.