User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jun 2007
Posts: 71
Reputation: Pro2000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Pro2000's Avatar
Pro2000 Pro2000 is offline Offline
Junior Poster in Training

preg_replace

  #1  
Oct 7th, 2007
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....
The great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: preg_replace

  #2  
Oct 7th, 2007
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!
Last edited by johny_d : Oct 7th, 2007 at 1:36 pm.
Reply With Quote  
Join Date: Jun 2007
Posts: 71
Reputation: Pro2000 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Pro2000's Avatar
Pro2000 Pro2000 is offline Offline
Junior Poster in Training

Re: preg_replace

  #3  
Oct 9th, 2007
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 great scientist see his web-site:
http://www.elnaggarzr.com/en
I'm sure that will be good for you!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC