php文件中的中文乱码该如何解决
下面的文件的注释部分含有部分中文,但是乱码了。各位大神,知道该如何把乱码部分解析成中文吗?
class Database
{
/*****************************************************
** MySQL????????????
*****************************************************/
var $db;
var $seconds;
var $queries;
var $timer = 0;
var $querytimes = array();
var $duration = '';
public $connectData=true;
/*****************************************************
** ??????,?????????
*****************************************************/
function Database($server = '', $username = '', $password = '', $database = '')
{
global $site_engine_root;
// $this->seconds = $this->currentTime();
if ('' == $server)
{
/*****************************************************
** ????????????????
*****************************************************/
$server = $GLOBALS['db_host'];
$username = $GLOBALS['db_user'];
$password = $GLOBALS['db_pass'];
$database = $GLOBALS['db_name'];
}
/*****************************************************
** ?????????
*****************************************************/
if (!$this->db = @mysql_pconnect($server, $username, $password))
{
if ($username == 'root' && $database == 'siteengine')
{
@header("Location:/install.php");
}
else
{
$this->connectData=false;
//$this->error("database connect fail");
}
}
if ($database&&$this->connectData===true)
{
if($this->version() > '4.1')
{
global $config_charset;
$config_charset = 'utf-8';
if(!$dbcharset && in_array(strtolower($config_charset), array('gbk', 'big5', 'utf-8')))
{
$dbcharset = str_replace('-', '', $config_charset);
}
if($dbcharset)
{
mysql_query("SET NAMES '$dbcharset'");
}
}
if($this->version() > '5.0.1')
{
mysql_query("SET sql_mode=''");
}
$this->selectDb($database);
}
return true;
}
/*****************************************************
** ????????????
*****************************************************/
function disconnect()
{
$result = mysql_close() or $this->error();
return $result;
}
/*****************************************************
** ????????
*****************************************************/
function selectDb($database)
{
global $multidomain,$site_engine_root,$tablepre,$db;
if (@mysql_select_db($database, $this->db))
{
return true;
}
else
{
if ($multidomain==1)
{
$query = $this->query("CREATE DATABASE ".$database);
@header("Location:/install.php");
// require $site_engine_root.'lib/query.php';
// $fp = @fopen($site_engine_root.'data/sql/siteengine.sql', "r");
// $query=@fread($fp, filesize($site_engine_root.'data/sql/siteengine.sql'));
// @fclose($fp);
// if($tablepre!='boka') $query=str_replace("boka_",$tablepre,$query);
// $sql_query = new query($query);
// $sql_query->doquery();
// @header("Location:/index.php");
}
$this->error("$database database connect error!");
}
}
/*****************************************************
** ???????????Web?????????У????????????????С???Web?????·???true???????????·???false
*****************************************************/
function isWebEnv()
{
if (isset($_SERVER['PHP_SELF']))
{
return true;
}
if (isset($GLOBALS['_SERVER']['PHP_SELF']))
{
return true;
}
return false;
}
/*****************************************************
** ???????????????????
*****************************************************/
function _textConvert($text)
{
if ($this->isWebEnv()) // Web????
{
return nl2br($text);
}
return $text;
}
/*****************************************************
** ?????????
*****************************************************/
function currentTime()
{
list($usec, $sec) = explode(' ', microtime());
$time = (double)$sec + (double)$usec;
return $time;
}
function show()
{
$message = "\n" . 'Processed in '
. ($this->currentTime() - $this->seconds) . ' second(s), '
. $this->queries . ' queries.' . "\n";
// return $this->_textConvert($message);
return $message;
}
/*****************************************************
** ?????????????????????
*****************************************************/
function error($var = false)
{
global $domain,$language,$site_engine_root;
// header('Content-Type: text/html; charset="utf-8"');
// @$error = "
An error was encountered |
"; // @$error .="SiteEngine\n".$GLOBALS['l_site']['dberror']." error in file \"".$_SERVER['PHP_SELF']."\"\n"; // @$error .= $GLOBALS['l_site']['errorinfo'].mysql_errno() . ': ' . mysql_error() . "\n"; if ($var) { $error .= "\n" . htmlspecialchars(@$GLOBALS['l_site']['errorsql']) . "\n" . $var . "\n"; } $error .=" |
if ($GLOBALS['sesettings']['system']['errorreport']==1)
{
$errorinfo = mysql_errno().":".rawurlencode(mysql_error());
$time = date("Ymd H:i:s",time());
// @file("http://error.siteengine.net/?domain=$domain&errorinfo=$errorinfo&username=$SESSION[username]&time=$time&language=$language");
}
if (file_exists($site_engine_root.'data/install.lock'))
{
die($this->_textConvert($error));
}
else
{
die($this->_textConvert($error));
// @header("Location:/install.php");
}
// ??????
return $error;
}
/*****************************************************
** ???????sql????
*****************************************************/
function query($sql)
{
global $opendebug,$admincp;
$this->start_timer();
if (($opendebug==1 && $admincp==0) || ($opendebug==2 && $admincp==1))
{
echo ''.$sql.';
';
echo gettotaltime().'
';
// echo $sql.';
';
}
$result = @mysql_query($sql, $this->db) or $this->error($sql);
++$this->queries;// ??????????
$this->querytimes[] = $this->stop_timer();
$lowersql=strtolower($sql);
$lowersql=trim($lowersql);
if(substr($lowersql,0,6) == "update" or substr($lowersql,0,6) == "delete" )
{
//echo "find update";
$affectrows=mysql_affected_rows();
return $affectrows;
}
return $result;
}
/*****************************************************
** ???????sql????
*****************************************************/
function unbufferedQuery($sql)
{
$result = mysql_unbuffered_query($sql, $this->db) or $this->error($sql);
return $result;
}
/*****************************************************
** ????????????????????
*****************************************************/
/*
* $result ??query()????????
* $fetch_mode ????????Ч???
* DB_FETCHMODE_ORDERED (default) ??????????????????
* DB_FETCHMODE_ASSOC ???????????????????
* DB_FETCHMODE_OBJECT ?????????????
*/
function fetchRow($result, $fetch_mode = false)
{
//assert('is_resource($result)');
switch ($fetch_mode)
{
case DB_FETCHMODE_OBJECT:
$row = @mysql_fetch_object($result);//$row->username
break;
case DB_FETCHMODE_ASSOC:
$row = @mysql_fetch_assoc($result);//$row['username']
break;
case DB_FETCHMODE_ORDERED:
default: // ?????
$row = @mysql_fetch_row($result);// 0,1,2,3
break;
}
return $row;
}
}
?>
回复讨论(解决方案)
显然是你打开的编码与文件的实际编码并不一致。
复制出来的是没办法还原的。你要看原始文件,用正确的编码打开
如果用不正确的编码打开后又保存了,基本上就没办法恢复了。
通过编辑器新建文件 编码设置 utf-8 把你文件复制进去,就不乱码。
3楼你试过?你用的是什么编辑器。我新建了一个txt,然后把它设为UTF-8,再把代码放进去,依然乱码。
把你的原始文件放到云盘上
3楼你试过?你用的是什么编辑器。我新建了一个txt,然后把它设为UTF-8,再把代码放进去,依然乱码。
notepad++ 你试试这个编辑器
1.你这个文件可以在别人给你的时候,就已经是乱码了。
2.文件的存储方改成 UTF8,可以使用UE , EditPlus 都可以,直接另存为,编码选UTF8。
好像不可逆了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
