note 68506 deleted from function.str-replace by philip

From: Date: Wed, 07 Oct 2009 08:04:58 +0000
Subject: note 68506 deleted from function.str-replace by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161462@lists.php.net to get a copy of this message
Note Submitter: webmaster at unitedscripters dot com ---- 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.

« previous php.notes (#161462) next »