Re: problem with ereg() and ereg_replace()
| From: | CC Zona | Date: | Sun, 02 Sep 2001 03:59:36 +0000 |
| Subject: | Re: problem with ereg() and ereg_replace() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65628@lists.php.net to get a copy of this message | ||
In article <01b201c13354$0ca601c0$0105050a@pony>,
stonix@stonix.com (Stonix) wrote:
> ereg_replace( "{key}", "word", $a_string);
>
> The web server will return following warnning msg:
>
> Warning: Invalid content of \{\} in /var/www/html/scrip.php on line #
In regex, the curly braces are special characters used to define the number
of repetitions to be matched, either as an exact number or as a range.
"a{2}" #"aa"
"abc(2,3}" #"abcabc" or "abcabcabc"
"abc{,2}" #"","abc", or "abcabc"
Are you trying to match the literal string "{key}"? 'Cuz if so, you might
as well just use str_replace since you're not really in need of ereg_*'s
special pattern matching. If you're trying to match a special character
with a regex, don't forget to either escape it or put it in a character
class:
ereg_replace( "\{key\}", "word", $a_string);
ereg_replace( "[{]key[}]", "word", $a_string);
--
CC