首页 > 编程技术 > php

php 返回mysql字符编码与删除字符编码

发布时间:2016-11-25 16:01

php 返回mysql字符编码与删除字符编码

function Ebak_GetSetChar($char){
 global $empire;
 if(empty($char))
 {
  return '';
 }
 $r=$empire->fetch1("SHOW COLLATION LIKE '".$char."';");
 return $r['Charset'];
}

//---------------------返回设置编码
function Ebak_ReturnSetNames($char){
 if(empty($char))
 {
  return '';
 }
 $dumpsql="DoSetDbChar('".$char."');rn";
 return $dumpsql;
}

//--------------------去除字段中的编码
function Ebak_ReplaceFieldChar($sql){
 global $phome_db_ver;
 if($phome_db_ver=='4.0'&&strstr($sql,' character set '))
 {
  $preg_str="/ character set (.+?) collate (.+?) /is";
  $sql=preg_replace($preg_str,' ',$sql);
 }
 return $sql;
}

php 显示mysql服务器所有数据库 SHOW DATABASES
$mydbname=$_GET['mydbname'];
$selectdbname=$phome_db_dbname;
if($mydbname)
{
 $selectdbname=$mydbname;
}
$db='';
if($canlistdb)
{
 $db.="<option value='".$selectdbname."'

selected>".$selectdbname."</option>";
}
else
{
 $sql=$empire->query("SHOW DATABASES");
 while($r=$empire->fetch($sql))
 {
  if($r[0]==$selectdbname)
  {$select=" selected";}
  else
  {$select="";}
  $db.="<option value='".$r[0]."'".$select.">".$r

[0]."</option>";
 }
}

php 创建目录函数教程

function DoMkdir($path){
 global $public_r;
 //不存在则建立
 if(!file_exists($path))
 {
  //安全模式
  if($public_r[phpmode])
  {
   $pr[0]=$path;
   FtpMkdir($ftpid,$pr);
   $mk=1;
  }
  else
  {
   $mk=@mkdir($path,0777);
  }
  @chmod($path,0777);
  if(empty($mk))
  {
   printerror("NotMkdir","history.go(-1)");
  }
 }
 return true;
}

php 读取,删除,写入文件实例教程

//-------------------------------删除文件
function DelFiletext($filename){
 @unlink($filename);
}

//---------------------------------取得文件内容
function ReadFiletext($filepath){
 $htmlfp=@fopen($filepath,"r");
 while($data=@fread($htmlfp,1000))
 {
  $string.=$data;
 }
 @fclose($htmlfp);
 return $string;
}

//--------------------------------写文件
function WriteFiletext($filepath,$string){
 global $filechmod;
 $string=stripSlashes($string);
 $fp=@fopen($filepath,"w");
 @fputs($fp,$string);
 @fclose($fp);
 if(empty($filechmod))
 {
  @chmod($filepath,0777);
 }
}

//--------------------------------写文件
function WriteFiletext_n($filepath,$string){
 global $filechmod;
 $fp=@fopen($filepath,"w");
 @fputs($fp,$string);
 @fclose($fp);
 if(empty($filechmod))
 {
  @chmod($filepath,0777);
 }
}

php 字符截取函数

function sub_str($title,$lengh){
 if(strlen($title)>$lengh)
 {
  $pp=2;
  $len=strlen($title);
  if($len%2<>0)
  {$pp=1;}
  $title=substr($title,0,$lengh-$pp);
  $title=$title.' …';
 }
 return $title;
}


//--------------------------------------字符截取函数2
function sub($Modi_Str,$start,$length,$mode = false){
 $n = 0;
 for($i=0;$i<$start;$i++){
  if(ord(substr($Modi_Str,$i,1))>0xa0){
   if($mode){
    $start++;
    $i++;
   }
   $n++;
  }
 }
 if(!$mode)$start = $start + $n%2;
 $The_length = $start+$length;
 for($i=$start;$i<$The_length;$i++){
  if(ord(substr($Modi_Str,$i,1))>0xa0){
   $The_Str.=substr($Modi_Str,$i,2);
   $i++;
   if($mode) $The_length++;
  }else{
   $The_Str.=substr($Modi_Str,$i,1);
  }
 }
 return $The_Str;
}

标签:[!--infotagslink--]

您可能感兴趣的文章: