List Info

Thread: note 68506 added to function.str-replace




note 68506 added to function.str-replace
user name
2006-07-30 13:50:36
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.p
hp.net/note/edit/68506
Del: integrated  -- ht
tp://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://m
aster.php.net/note/delete/68506/spam
Del: non-english -- h
ttp://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://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )