[nycphp-talk] Bug in PHundamentals function?
Aaron Fischer
agfische at email.smith.edu
Mon Oct 3 16:56:32 EDT 2005
I've been thinking of implementing the PHundamentals function for fixing
magic quotes when on a shared server:
(http://www.nyphp.org/phundamentals/storingretrieving.php)
The line in question:
return $sybase ? str_replace ('\'\'', '\'', $var) : stripslashes ($var);
I broke the str_replace and stripslashes out into separate code to test
and make sure I understand what was going on.
When testing, the str_replace wasn't working as is with the search and
replace string surrounded by single quotes. After checking the php
manual , I changed the search and replace text to be surrounded by
double quotes and it worked correctly.
Should the PHundamentals function be changed to have double quotes?
Here's the code I used to test:
// test sybase str_replace with single quotes - doesn't appear to
produce desired result
echo '<br /><br />';
$sb_string = "I\'\'m heading out on the road";
$sb_string_new = str_replace('\'\'', '\'', $sb_string);
echo 'Sybase string is ' . $sb_string . '<br />';
echo 'String replace produces ' . $sb_string_new . '<br />';
// test sybase str_replace with double quotes - appears to produce
desired result
echo '<br />';
$sb_string_new = str_replace("\'\'", "\'", $sb_string);
echo 'Sybase string is ' . $sb_string . '<br />';
echo 'String replace produces ' . $sb_string_new . '<br />';
And the output:
Sybase string is I\'\'m heading out on the road
String replace produces I\'\'m heading out on the road
Sybase string is I\'\'m heading out on the road
String replace produces I\'m heading out on the road
Thoughts?
-Aaron
More information about the talk
mailing list