Bug #1099: Strange behaviour of regular expressions
| From: | thifi at telnet dot hu | Date: | Thu, 28 Jan 1999 13:47:24 +0000 |
| Subject: | Bug #1099: Strange behaviour of regular expressions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-3758@lists.php.net to get a copy of this message | ||
From: thifi@telnet.hu
Operating system: Linux, Debian Slink, 2.2.0
PHP version: 3.0.6
PHP Bug Type: Misbehaving function
Bug description: Strange behaviour of regular expressions
There is the following line in a text file:
1.word ##test,hello### 2.word 3.word ##test2,hello###, 4.word!
I'd like to replace every ##...### enclosed characters with a string:
In perl it works like this:
#!/usr/bin/perl
open(F,"<test.txt");
while(<F>) {
chomp;
s/##.*?,.*?###/REPLACED/g;
print "$_\n";
}
close(F);
output:
# ./test.pl
1.word REPLACED 2.word 3.word REPLACED, 4.word!
But in php3:
#!/usr/lib/cgi-bin/php3 -q
<?
$file = fopen("test.txt","r");
while(!feof($file)) {
$s = chop(fgets($file,10000));
$s = ereg_replace("##.*?,.*?###","REPLACED",$s);
echo("$s\n");
}
fclose($file);
?>
output is:
# ./test.php3
1.word REPLACED, 4.word!
So why can't I use .*? in a regular expression function?
If I made a mistake then sorry for the report.
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net