preg_replace
Moderator: General Moderators
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
preg_replace
does anyone know why preg_replace would return and error like
Warning: Unknown modifier '(' on line 27
but if i change it to ereg_replace or eregi_replace it works fine, and i really need the limit option of preg_replace.
Warning: Unknown modifier '(' on line 27
but if i change it to ereg_replace or eregi_replace it works fine, and i really need the limit option of preg_replace.
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
each preg-expression starts with an delimeter that you may choose freely (quite). common chars are / or !. You mark the end of the expression with the same character (maybe followed by some modifiers like m for multiline).
I assume your expression looks like '\([0-9]*\)' or simliar.
the preg-function starts to parse the string, finds \ as first character, interprets it as delimeter, finds the next occurence and then tries to parse the following chars as modifiers; in your case ), but this isn't a valid modifier.
in simple words:
ereg_xyz('expr') -> preg_xyz('/expr/'); or
ereg_xyz('expr') -> preg_xyz('!expr!'); or
...
I assume your expression looks like '\([0-9]*\)' or simliar.
the preg-function starts to parse the string, finds \ as first character, interprets it as delimeter, finds the next occurence and then tries to parse the following chars as modifiers; in your case ), but this isn't a valid modifier.
in simple words:
ereg_xyz('expr') -> preg_xyz('/expr/'); or
ereg_xyz('expr') -> preg_xyz('!expr!'); or
...
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Regarding the speed of preg_... ereg_... etc I've found this handy table at
http://php.weblogs.com/
http://php.weblogs.com/
"So I just benchmarked the following search methods, searching for my name in a string 6044 bytes long. My name was at the very end of the string to exercise the code. Here's the results for 500 searches on PHP 4.2.1, on a 800 Mhz Windows 2000 server:"
- $rez = strpos($SS,'John Lim'); ------ 0.0188 seconds
$rez = strstr($SS,'John Lim'); ------ 0.0294 seconds
$rez = preg_match('/John Lim/',$SS); ------ 0.0307 seconds
$rez = ereg('John Lim',$SS); ------ 1.5600 seconds
$rez = preg_match('/John Lim/i',$SS); ------ 0.0387 seconds
$rez = preg_match('/[a-z ]+Lim/i',$SS);------ 0.0573 seconds
$rez = preg_match('/John[ a-z]+/i',$SS)------ 0.0403 seconds
$rez = eregi('John[ a-z]*',$SS); ------ 2.1200 seconds
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm
-
Silver_Eclipse
- Forum Commoner
- Posts: 61
- Joined: Sun Aug 18, 2002 7:26 pm