<?

/**********************************************************************/
/*
* CLASS NAME : IniFile
* INI 文件读/写
* Copyright (c) 2003 Kinlam chen
*/
if (!defined("INI_FILE_PHP_CLASS"))
{
define("INI_FILE_PHP_CLASS",true); class IniFile
{
var $filename = "";
var $results = array();  
var $loaded = false;

function IniFile($filename)
{
$this->setFile($filename);
}

function setFile($filename)
{
$this->filename = $filename;
$this->clear();
}

function clear()
{
$this->loaded = false;
unset($this->results);
}

function loadFile() 
{
if(file_exists($this->filename) && is_file($this->filename) && 
   is_readable($this->filename))
{
$this->clear();
$this->results = parse_ini_file($this->filename,true);
$this->loaded = true;
}
}

function getValue($section, $option)
{
if(!($this->loaded))
{
$this->loadFile();
}
if(isset($this->results[$section]))
{
$sectionValues = $this->results[$section];
if(is_array($sectionValues))
{
if(isset($sectionValues[$option]))
{
return $sectionValues[$option];
}
else
{
return "";
}
}
else
{
return $sectionValues;
}
}
else
{
return "";
}
}

function getSection($section)
{
if(!($this->loaded))
{
$this->loadFile();
}
if(isset($this->results[$section]))
{
$sectionValues = $this->results[$section];
if(is_array($sectionValues))
{
return $sectionValues;
}
else
{
$tmp = array();
$tmp[$section] = $sectionValues;
return $tmp;
}
}
return array();
}

function setValue($section, $option, $value, $write = false)
{
if($section != "")
{
$this->results[$section][$option] = $value;
}
else
{
$this->results[$option] = $value;
}
if($write == true)
{
return $this->writeFile;
}
return true;
} function writeFile()
{
$ok = true;
$fp = fopen($this->filename,"wb");
if(!$fp)
{
$ok = false;
}
else
{
if(isset($this->results))
{
while(list($section, $values) = each($this->results))
{
if(is_array($values))
{
$res = fwrite($fp,"[$section]\n");
if($res == -1)
{
$ok = false;
break;
}
while(list($option, $value) = each($values))
{
$res = fwrite($fp,"$option=$value\n");
if($res == -1)
{
$ok = false;
break;
}
}
if($ok == false) break;
}
else
{
$res = fwrite($fp,"$section=$values\n");
if($res == -1)
{
$ok = false;
break;
}
}
}
}
if(fclose($fp) == -1)
{
$ok = false;
}
}
return $ok;
}
}

function getValueFromINI($filename, $section, $option)
{
$inifile = new IniFile($filename);
return $inifile -> getValue($section,$option);
}
}
//Program writen by sadly www.phpx.com function gb2utf8($gb)
{

if(!trim($gb))
return $gb;
$filename="../Lib/gb2312.txt";
$tmp=file($filename);
$codetable=array();
while(list($key,$value)=each($tmp))
$codetable[hexdec(substr($value,0,6))]=substr($value,7,6); $utf8="";
while($gb)
{
if (ord(substr($gb,0,1))>127)
{
//$this=unset($this);
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb));
$utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));
}
else
{
$gb=substr($gb,1,strlen($gb));
$utf8.=u2utf8(substr($gb,0,1));
}
} $ret="";
for($i=0;$i<strlen($utf8);$i+=3)
$ret.=chr(substr($utf8,$i,3)); return $ret;
} function u2utf8($c)
{
for($i=0;$i<count($c);$i++)
$str="";
if ($c < 0x80) {
$str.=$c;
}
else if ($c < 0x800) {
$str.=(0xC0 | $c>>6);
$str.=(0x80 | $c & 0x3F);
}
else if ($c < 0x10000) {
$str.=(0xE0 | $c>>12);
$str.=(0x80 | $c>>6 & 0x3F);
$str.=(0x80 | $c & 0x3F);
}
else if ($c < 0x200000) {
$str.=(0xF0 | $c>>18);
$str.=(0x80 | $c>>12 & 0x3F);
$str.=(0x80 | $c>>6 & 0x3F);
$str.=(0x80 | $c & 0x3F);
}
return $str;
} function browseinfo() {
$browser="";$browserver="";
$Browsers =array("Lynx","MOSAIC","AOL","Opera","JAVA","MacWeb","WebExplorer","OmniWeb");
$Agent = $GLOBALS["HTTP_USER_AGENT"];
for ($i=0; $i<=7; $i++) {
if (strpos($Agent,$Browsers[$i])) {
$browser = $Browsers[$i];
$browserver ="";
}
} if (ereg("Mozilla",$Agent) && !ereg("MSIE",$Agent)) {
  $temp =explode("(", $Agent); $Part=$temp[0];
  $temp =explode("/", $Part); $browserver=$temp[1];
  $temp =explode(" ",$browserver); $browserver=$temp[0];
  $browserver =preg_replace("/([\d\.]+)/","\\1",$browserver);
  $browserver = " $browserver";
  $browser = "Netscape Navigator";
}
if (ereg("Mozilla",$Agent) && ereg("Opera",$Agent)) {
  $temp =explode("(", $Agent); $Part=$temp[1];
  $temp =explode(")", $Part); $browserver=$temp[1];
  $temp =explode(" ",$browserver);$browserver=$temp[2];
  $browserver =preg_replace("/([\d\.]+)/","\\1",$browserver);
  $browserver = " $browserver";
  $browser = "Opera";
}
if (ereg("Mozilla",$Agent) && ereg("MSIE",$Agent)) {
$temp = explode("(", $Agent); $Part=$temp[1];
$temp = explode(";",$Part); $Part=$temp[1];
$temp = explode(" ",$Part);$browserver=$temp[2];
$browserver =preg_replace("/([\d\.]+)/","\\1",$browserver);
$browserver = " $browserver";
$browser = "Internet Explorer (IE)";
}
if ($browser!="") {
$browseinfo = "$browser$browserver";
} else {
$browseinfo = "Unknown Browse";
} return $browseinfo; }
/******************************/?>
其中$thise在PHP4中可以用,但在PHP5.1中就不能用,请各位多多指教....

解决方案 »

  1.   

    $this能不能换别的变量         $this=substr($gb,0,2);
    $gb=substr($gb,2,strlen($gb));
    $utf8.=u2utf8(hexdec($codetable[hexdec(bin2hex($this))-0x8080]));
      

  2.   

    $this=substr($gb,0,2);
    php5就不允许这样了
      

  3.   

    知道为什么不能再这么写了吗?
    因为php5引入了__toString方法<?php
    // Declare a simple class
    class TestClass
    {
        public $foo;    public function __construct($foo) {
            $this->foo = $foo;
    echo $this; //注意这里
        }    public function __toString() {
            return $this->foo;
        }
    }$class = new TestClass('Hello');
    echo $class;
    ?> 其实本来就不应该在类中使用$this做变量名,很容易产生歧义的
      

  4.   

    朋友,请关注一下此帖:
    http://community.csdn.net/Expert/topic/4338/4338855.xml?temp=.8305628