Date: 01/28/99
- Next message: Rasmus Lerdorf: "[PHP-DEV] ANNOUNCE: libapreq-0.30_01 (fwd)"
- Previous message: Dave Walton: "Re: [PHP-DEV] Interesting sleep() side-effect"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: thifi <email protected>
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 <email protected> For help: php-dev-help <email protected>
- Next message: Rasmus Lerdorf: "[PHP-DEV] ANNOUNCE: libapreq-0.30_01 (fwd)"
- Previous message: Dave Walton: "Re: [PHP-DEV] Interesting sleep() side-effect"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

