Hi.
I've got this simple snippet:
<?php
class dataProcessor{
function dataProcessor()
{
if(get_class($this)=='dataProcessor'||!is_subclass_of($this)){
trigger_error('This class is abstract.It cannot be instantiated!',E_USER_ERROR);
}
}
// define generic methods
function toString(){}
function toArray(){}
function toXML(){}
}
class fileProcessor extends dataProcessor{
var $file;
function fileProcessor($file){
if(!file_exists($file)){
trigger_error('Invalid file!',E_USER_ERROR);
exit();
}
$this->file=$file;
}
// returns filedata as string with <br /> tags
function toString(){
return nl2br(file_get_contents($this->file));
}
// returns file data as array
function toArray(){
return file($this->file);
}
// returns file data as XML
function toXML(){
header('Content-Type: text/xml');
$xml='<?xml version="1.0" encoding="utf-8"?>'."\n";
$xml.='<filedata>'."\n";
$filedata=$this->toArray();
foreach($filedata as $row){
$xml.='<filenode>'.htmlentities(trim($row)).'</filenode>'."\n";
}
$xml.='</filedata>';
return $xml;
}
}
$obj = new fileProcessor("test.txt");
echo $obj->toXML();
?>
Well
with FF (1.5) works fine (it shows xml without error)
with Opera 9 works quite fine (it shows simple text without error)
with IE 6 doesn't work (it shows error with invalid charater )
Here the line that trigger an error
I’m going to derive another child class from the parent “dataProcessor” class, so you can understand how the same
I tried with <?xml version="1.0" encoding="iso-8859-1"?> and
works with IE as well but it doesn't with Opera 9 (simple txt)
I can't figure out why 😕
Can you explain me, please ?
Take care.