php 批量替换表字段全角字符到半角

 
更多
<?php
set_time_limit(0);
require_once('include/common.inc.php');

function Field_SBC_DBC($Field){
	$DBC = Array ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-', ' ', ':', '.', ',', '/', '%', '#', '!', '@', '&', '(', ')', '<', '>', '"', ''', '?', '[', ']', '{', '}', '\', '|', '+', '=', '_', '^', '¥', ' ̄', '`' );
	$SBC = Array ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '-', ' ', ':', '.', ',', '/', '%', '#', '!', '@', '&', '(', ')', '<', '>', '"', "\'", '?', '[', ']', '{', '}', "\\\\", '|', '+', '=', '_', '^', '$', '~', '`' );
	if ( count($DBC) == count($SBC) ){
		$str="";
		for($i=0;$i<=count($DBC)-1;$i++){
			if($i==0 && empty($str)){
				$str="`{$Field}`";
			}
			$str="REPLACE({$str},'{$DBC[$i]}','{$SBC[$i]}')";
		}
	}
	if(!empty($str)){
		//$str="`{$Field}`={$str}";
		$str="`{$Field}`=trim(replace({$str},'\r\n', ' '))";
	}
	return $str;
}

$sql = "SHOW COLUMNS FROM `#@__oldyuyue`;";
$dsql->SetQuery ($sql);
$dsql->Execute ();
while ($row=$dsql->GetArray()){
	$Update="UPDATE `crm_oldyuyue` SET ".Field_SBC_DBC($row['Field']);
	echo "{$row['Field']} (" .$dsql->ExecuteNoneQuerys($Update).")<br/>";
}

exit();
UPDATE `crm_oldyuyue` SET `xingming`=REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(`xingming`,'0','0'),'1','1'),'2','2'),'3','3'),'4','4'),'5','5'),'6','6'),'7','7'),'8','8'),'9','9'),'A','A'),'B','B'),'C','C'),'D','D'),'E','E'),'F','F'),'G','G'),'H','H'),'I','I'),'J','J'),'K','K'),'L','L'),'M','M'),'N','N'),'O','O'),'P','P'),'Q','Q'),'R','R'),'S','S'),'T','T'),'U','U'),'V','V'),'W','W'),'X','X'),'Y','Y'),'Z','Z'),'a','a'),'b','b'),'c','c'),'d','d'),'e','e'),'f','f'),'g','g'),'h','h'),'i','i'),'j','j'),'k','k'),'l','l'),'m','m'),'n','n'),'o','o'),'p','p'),'q','q'),'r','r'),'s','s'),'t','t'),'u','u'),'v','v'),'w','w'),'x','x'),'y','y'),'z','z'),'-','-'),' ',' '),':',':'),'.','.'),',',','),'/','/'),'%','%'),'#','#'),'!','!'),'@','@'),'&','&'),'(','('),')',')'),'<','<'),'>','>'),'"','"'),''','\''),'?','?'),'[','['),']',']'),'{','{'),'}','}'),'\','\\'),'|','|'),'+','+'),'=','='),'_','_'),'^','^'),'¥','$'),' ̄','~'),'`','`');

打赏

本文固定链接: https://www.cxy163.net/archives/1113 | 绝缘体

该日志由 绝缘体.. 于 2016年05月12日 发表在 首页 分类下,
原创文章转载请注明: php 批量替换表字段全角字符到半角 | 绝缘体

报歉!评论已关闭.