note 68506 added to function.str-replace
| From: | webmaster at unitedscripters dot com | Date: | Sun, 30 Jul 2006 13:50:36 +0000 |
| Subject: | note 68506 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115350@lists.php.net to get a copy of this message | ||
You may have decided to save in a non ANSI format a file so that a few fancy chars that you plan to
replace can be viewed by your human eyes too (aren't all those empty rectangles a curse?).
Fine. All works just fine in the file, and all the replacements occur as intended.
You make a class out of those codes.
Then you put this non ANSI encoded file in your includes folder. Isn't it a nice class?
Well, don't call in such class as an include into another file, if the latter is ANSI : the
char look up tables will NOT match, and the latter file (say the caller) will (I guess) feed ANSI
codes to the included file (say the called) and you will spend a day wondering why the class methods
work 100% well when you perform replacements directly from within the called, and yet the very same
methods, even with the very same copied-and-pasted examples, fail miserably when performed from
within the caller.
A very "stimulating" debugging!
I just came out from a night spent on this. I just forgot the included class file wasn't saved
as an ANSI.
<?php
class regexp{
//blah blah...
var $toascii=array( 'Ã' => 'A');
//blah blah
function toascii_replace($input, $addSlashes=0){
return (!$addSlashes)? strtr($input, $this->toascii): addslashes( strtr($input,
$this->toascii) );
}
}
$r=new regexp();
$input='Ã';
print $r->toascii_replace($input);//prints A
?>
Now save that class (remove the print statement too) in a format that isn't ANSI, say UTF-8.
Then do:
<?php
include_once('regexp.php');
$r=new regexp();
$input='Ã';
print $r->toascii_replace($input);//prints... Ã
?>
IDENTICAL codes, different results.
note: the class uses strtr but would happen with all replacing oriented functions, and I can pester
all the documentations. Maybe I worked out the wrong reason, but the behaviour occurs.
----
Server IP: 213.92.11.19
Probable Submitter: 84.221.73.161
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- http://master.php.net/note/edit/68506
Del: integrated -- http://master.php.net/note/delete/68506/integrated
Del: useless -- http://master.php.net/note/delete/68506/useless
Del: bad code -- http://master.php.net/note/delete/68506/bad+code
Del: spam -- http://master.php.net/note/delete/68506/spam
Del: non-english -- http://master.php.net/note/delete/68506/non-english
Del: in docs -- http://master.php.net/note/delete/68506/in+docs
Del: other reasons-- http://master.php.net/note/delete/68506
Reject -- http://master.php.net/note/reject/68506
Search -- http://master.php.net/manage/user-notes.php