ID: 14879
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Status: Open
Bug Type: Scripting Engine problem
Operating System: Linux-Mandrake 8.1
PHP Version: 4.0.6
New Comment:

<?      
## Assign a bit of HTML to two source variables
#
        $space_source_text      = 
        $null_source_text       = "<b>PHP</b> <i>is</i> a useful <u>tool</u>";


## Replace a substring within the the source variables
#       with another substring
        $null_source_text       = ereg_replace("",      "|" $null_source_text);
        $space_source_text      = ereg_replace(" ",     "|", $space_source_text);


## Print the new values of the source variables
#
        print("This is the result of calling ereg_replace with an empty
parameter.<hr>$null_source_text<br><br><br>");
        print("This is the result of calling ereg_replace with a space as the
value of the parameter.<hr>$space_source_text");


## Conclusion
#
#       To me it seems that there are two significant points to make about the
behaviour of ereg_replace as demonstrated
#       in this example.
#       
#       The first point is that, when passing an empty value in the first
parameter, the ereg_replace function inserts
#       the second parameter between every character in the string, therefor
increasing the overall size of the string.
#       It is inserting -- not replacing as the function name implies
#
#       The second point is that, when passing an empty value in the first
parameter, the ereg_replace function does
#       not evaluate the HTML tags so that they are correctly rendered to the
browser.
#
#       Please keep in mind that I have yet to see the definition of
ereg_replace.
#
#       At first, I thought the ereg_replace function was possibly checking to
see if the first parameter was empty, and if
#       so, return execution immediatly to the caller. However, this doesn't
appear to be the case because it is obviously
#       transversing the character array because it is inserting the second
parameter between each character.
#
#       I'm guessing that PHP does some internal escaping of HTML characters
and the empty first parameter is somehow
#       goofing up the translation back to clean HTML
#
##
?>


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

[2002-01-05 18:33:02] [EMAIL PROTECTED]

<?      
        ## Assign a bit of HTML to two source variables
        #
                $space_source_text      = 
                $null_source_text       = "<b>PHP</b> <i>is</i> a useful <u>tool</u>";


        ## Replace a substring within the the source variables
        #       with another substring
                $null_source_text       = ereg_replace("",      "|",    
$null_source_text);
                $space_source_text      = ereg_replace(" ",     "|",    
$space_source_text);


        ## Print the new values of the source variables
        #
                print("This is the result of calling ereg_replace with an empty
parameter.<hr>$null_source_text<br><br><br>");
                print("This is the result of calling ereg_replace with a space as the
value of the parameter.<hr>$space_source_text");


        ## Conclusion
        #
        #       To me it seems that there are two significant points to make about
the behaviour of ereg_replace as demonstrated
        #       in this example.
        #       
        #       The first point is that, when passing an empty value in the first
parameter, the ereg_replace function inserts
        #       the second parameter between every character in the string, therefor
increasing the overall size of the string.
        #       It is inserting -- not replacing as the function name implies
        #
        #       The second point is that, when passing an empty value in the first
parameter, the ereg_replace function does
        #       not evaluate the HTML tags so that they are correctly rendered to the
browser.
        #
        #       Please keep in mind that I have yet to see the definition of
ereg_replace.
        #
        #       At first, I thought the ereg_replace function was possibly checking
to see if the first parameter was empty, and if
        #       so, return execution immediatly to the caller. However, this doesn't
appear to be the case because it is obviously
        #       transversing the character array because it is inserting the second
parameter between each character.
        #
        #       I'm guessing that PHP does some internal escaping of HTML characters
and the empty first parameter is somehow
        #       goofing up the translation back to clean HTML
        #
        ##
?>

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



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


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to