Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #29348 : ereg_replace strange behavior
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 4th March 00:35
External User
 
Posts: 1
Default #29348 : ereg_replace strange behavior



ID: 29348
Updated by: sniper@php.net
Reported By: mobanajp at yahoo dot co dot jp
-Status: Open
+Status: Bogus
Bug Type: Regexps related
Operating System: Win XP
PHP Version: 4.3.7
New Comment:

Read the full page first into $buf.

Previous Comments:
------------------------------------------------------------------------

[2004-07-23 11:00:44] mobanajp at yahoo dot co dot jp

Description:
------------
Please compare this 3 script :
1. Simple Open a Page (everything going well)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);
echo $buf;
?>

2. Simple Open A Page and eliminate the line break (THE PAGE CUT IN
MIDDLE)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

3. Open page using File and eliminate line-break per array elements
(everything going well)
<?
$buf = file("http://poxy.x0.com/deai/html/index.html");
foreach($buf as $key=> $value) {
$buf[$key] = ereg_replace("\r|\n", "", $buf[$key]);
}
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

Reproduce code:
---------------
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

Expected result:
----------------
the page without break line

Actual result:
--------------
half of the page without break line


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=29348&edit=1
  Reply With Quote


  sponsored links


2 4th March 00:35
External User
 
Posts: 1
Default #29348 : ereg_replace strange behavior



ID: 29348
Updated by: moriyoshi@php.net
Reported By: mobanajp at yahoo dot co dot jp
-Status: Bogus
+Status: Verified
Bug Type: Regexps related
Operating System: Win XP
PHP Version: 4.3.7
New Comment:

It seems the way to read the page into $buf doesn't
matter. Just a bug in ereg_replace() as simply
replacing it by preg_replace() worked.


<?php
$buf = file("http://poxy.x0.com/deai/html/index.html");
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

This also gives a wrong result.

Previous Comments:
------------------------------------------------------------------------

[2005-01-11 06:54:36] sniper@php.net

Read the full page first into $buf.


------------------------------------------------------------------------

[2004-07-23 11:00:44] mobanajp at yahoo dot co dot jp

Description:
------------
Please compare this 3 script :
1. Simple Open a Page (everything going well)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);
echo $buf;
?>

2. Simple Open A Page and eliminate the line break (THE PAGE CUT IN
MIDDLE)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

3. Open page using File and eliminate line-break per array elements
(everything going well)
<?
$buf = file("http://poxy.x0.com/deai/html/index.html");
foreach($buf as $key=> $value) {
$buf[$key] = ereg_replace("\r|\n", "", $buf[$key]);
}
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

Reproduce code:
---------------
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

Expected result:
----------------
the page without break line

Actual result:
--------------
half of the page without break line


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=29348&edit=1
  Reply With Quote
3 4th March 00:35
External User
 
Posts: 1
Default #29348 : ereg_replace strange behavior


ID: 29348
Updated by: moriyoshi@php.net
Reported By: mobanajp at yahoo dot co dot jp
-Status: Verified
+Status: ****yzed
Bug Type: Regexps related
Operating System: Win XP
PHP Version: 4.3.7
New Comment:

The following code just doesn't work:

<?php
echo ereg_replace("a", "a", "abc\0def\0");
?>

Because inserted null bytes (¥x00) prevents it from
properly concatenating substrings delimited by the
replacement.

dunno if this is a limitation of ereg_* though.


Previous Comments:
------------------------------------------------------------------------

[2005-01-11 07:27:15] moriyoshi@php.net

It seems the way to read the page into $buf doesn't
matter. Just a bug in ereg_replace() as simply
replacing it by preg_replace() worked.


<?php
$buf = file("http://poxy.x0.com/deai/html/index.html");
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

This also gives a wrong result.


------------------------------------------------------------------------

[2005-01-11 06:54:36] sniper@php.net

Read the full page first into $buf.


------------------------------------------------------------------------

[2004-07-23 11:00:44] mobanajp at yahoo dot co dot jp

Description:
------------
Please compare this 3 script :
1. Simple Open a Page (everything going well)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);
echo $buf;
?>

2. Simple Open A Page and eliminate the line break (THE PAGE CUT IN
MIDDLE)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

3. Open page using File and eliminate line-break per array elements
(everything going well)
<?
$buf = file("http://poxy.x0.com/deai/html/index.html");
foreach($buf as $key=> $value) {
$buf[$key] = ereg_replace("\r|\n", "", $buf[$key]);
}
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

Reproduce code:
---------------
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

Expected result:
----------------
the page without break line

Actual result:
--------------
half of the page without break line


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=29348&edit=1
  Reply With Quote
4 9th March 06:45
External User
 
Posts: 1
Default #29348 : ereg_replace strange behavior


ID: 29348
Updated by: sniper@php.net
Reported By: mobanajp at yahoo dot co dot jp
-Status: ****yzed
+Status: Bogus
Bug Type: Regexps related
Operating System: Win XP
PHP Version: 4.3.7
New Comment:

It's yet another ereg_* limitation: Just use PCRE instead.

Previous Comments:
------------------------------------------------------------------------

[2005-01-11 07:34:14] moriyoshi@php.net

The following code just doesn't work:

<?php
echo ereg_replace("a", "a", "abc\0def\0");
?>

Because inserted null bytes (¥x00) prevents it from
properly concatenating substrings delimited by the
replacement.

dunno if this is a limitation of ereg_* though.

------------------------------------------------------------------------

[2005-01-11 07:27:15] moriyoshi@php.net

It seems the way to read the page into $buf doesn't
matter. Just a bug in ereg_replace() as simply
replacing it by preg_replace() worked.


<?php
$buf = file("http://poxy.x0.com/deai/html/index.html");
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

This also gives a wrong result.


------------------------------------------------------------------------

[2005-01-11 06:54:36] sniper@php.net

Read the full page first into $buf.


------------------------------------------------------------------------

[2004-07-23 11:00:44] mobanajp at yahoo dot co dot jp

Description:
------------
Please compare this 3 script :
1. Simple Open a Page (everything going well)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);
echo $buf;
?>

2. Simple Open A Page and eliminate the line break (THE PAGE CUT IN
MIDDLE)
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

3. Open page using File and eliminate line-break per array elements
(everything going well)
<?
$buf = file("http://poxy.x0.com/deai/html/index.html");
foreach($buf as $key=> $value) {
$buf[$key] = ereg_replace("\r|\n", "", $buf[$key]);
}
$buf = implode("", $buf);
$buf = ereg_replace("\r|\n", "", $buf);

echo $buf;
?>

Reproduce code:
---------------
<?
$buf = "";
$fp = fopen("http://poxy.x0.com/deai/html/index.html", "r");
if($fp) while(!feof($fp)) $buf.=fread($fp, 1024);

$buf = ereg_replace("\r|\n", "", $buf);
echo $buf;
?>

Expected result:
----------------
the page without break line

Actual result:
--------------
half of the page without break line


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=29348&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666