•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,533 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,919 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1422 | Replies: 2
![]() |
Hi guys, I wrote:
The browser said:
________________________________________________
The error was in the $enn=preg_replace....
<?php
$WACnt=33;
while($WACnt>=0)
{
require("Wordsarray.php");
$enn=preg_replace("/".$normal[$WACnt]."/i",$tidied[$WACnt],$enn);
$WACnt--;
}
?>•
•
•
•
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....
The great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
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!
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!
Last edited by johny_d : Oct 7th, 2007 at 1:36 pm.
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.
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.
The great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- preg_replace regular expression problem with bbcode (PHP)
- Form not sending email (PHP)
- This ought to be simple - extra spaces (PHP)
- PHP .tpl format template help! URGENT! (PHP)
- XHTML Complient parser? (HTML and CSS)
- Scanning for links (PHP)
- Having trouble with links on PHP site! Any help would be great! (PHP)
Other Threads in the PHP Forum
- Previous Thread: Parse html
- Next Thread: Session Login


Linear Mode