ID:               23984
 User updated by:  ltfrench at vt dot edu
-Summary:          chr(0) in string causes string truncation
 Reported By:      ltfrench at vt dot edu
-Status:           Bogus
+Status:           Open
-Bug Type:         Strings related
+Bug Type:         PCRE related
 Operating System: Redhat 8.0
 PHP Version:      4.3.1
 New Comment:

Ok, this will teach me to try to write new test cases.  The first test
case was bogus, I'm a boob.  

The problem I am really having with is with preg_replace().

<?php
$string = "string\0withnull";
// array of bad ascii values I want to ditch
$ary = array( chr(0), chr(1) );
foreach( $ary as $badchar ){
   pattern = "/$badchar/";
   replacement = "TEST";
   $string = preg_replace($pattern, $replacement, $string);
}
echo $string;
?>

This generates 
Warning: No ending delimiter '/' found in /home/www/web_root/lance.php
on line 19

Which leads me to believe that my $pattern string got truncated without
the trailing / when used in preg_replace.


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

[2003-06-03 10:09:07] [EMAIL PROTECTED]

PHP is looking for a variable named $nullwithnull so to make this work,
you must use "string{$null}withnull"...

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

[2003-06-03 08:56:54] ltfrench at vt dot edu

This problem is very similar to: http://bugs.php.net/bug.php?id=14580
and also http://bugs.php.net/bug.php?id=18341 but seems to have cropped
up again.

Inserting a null character into a string with the chr() function causes
the string to be truncated.

<?php
$null = chr(0);
$a = "string\0withnull";
$b = "string$nullwithnull";

echo $a . "\n";
echo $b . "\n";

echo strlen($a) . "\n";
echo strlen($b) . "\n";
?>

Output:
stringwithnull
string
15
6

I encountered this with a generic php 4.3.1 setup.

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


-- 
Edit this bug report at http://bugs.php.net/?id=23984&edit=1

Reply via email to