|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-01-05 18:33 UTC] jhise at linuxforbusiness dot org
<?
## 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
#
##
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 09:00:01 2025 UTC |
<? ## 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 # ## ?>