posts - 6, comments - 6, trackbacks - 0, articles - 0

2007年4月13日

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/* Create a new XMLHttpRequest object to talk to the Web server */
function getbw()
{
    var xmlhttp;
 try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } catch (oc) {
   xmlhttp=null;
  }
 }
 if(!xmlhttp && typeof XMLHttpRequest != "undefined")
  xmlhttp = new XMLHttpRequest();
return xmlhttp;
}
 
    function IDRequest(n) {
 xmlhttp=getbw();
    //定义收到服务器的响应后需要执行的JavaScript函数
    url=n+document.getElementById('163id').value;//定义网址参数
    alert(url);
 xmlhttp.open("GET",url, true);       
 xmlhttp.send(null);        
    //xmlhttp_request=getXMLRequester();//调用创建XMLHttpRequest的函数       
    xmlhttp.onreadystatechange = doContents;//调用doContents函数       

    }   
    function doContents() {       
    if (xmlhttp.readyState == 4) {// 收到完整的服务器响应           
        if (xmlhttp.status == 200) {//HTTP服务器响应的值OK
  
       document.getElementById('message').innerHTML = xmlhttp.responseText;//将服务器返回的字符串写到页面中ID为message的区域           
        } else {               
        alert(xmlhttp.status);
        }       
        }   
        }
        </script>
</head>
<body>
<input type="text" id="163id" />
<input type="button" value="校验" onclick="IDRequest('check.php?userid=')" />
<div id="message"></div>
</body>
</html>

posted @ 2007-04-23 19:10 吴涛涛 阅读(376) | 评论 (0)编辑 收藏

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript生成上传图像预览功能</title>
</head>
<body>
<INPUT id=photo1 style="WIDTH: 350px"   onpropertychange="if(event.propertyName=='value') preview1.src=photo1.value.replace(/\\/g,'/')"
            type=file name=photo1>
<br />
<IMG id=preview1 height=66 src="图片博客-上传图片_files/sampe3.jpg"
width=66 name=preview1>
</body>
</html>

posted @ 2007-04-23 19:09 吴涛涛 阅读(425) | 评论 (0)编辑 收藏

<?
//utf-8->gb2312函数,本程序没有用到,仅供参考
function u2utf82gb($c){
  $str="";
  if ($c < 0x80) {
      $str.=$c;
  } else if ($c < 0x800) {
      $str.=chr(0xC0 | $c>>6);
      $str.=chr(0x80 | $c & 0x3F);
  } else if ($c < 0x10000) {
      $str.=chr(0xE0 | $c>>12);
      $str.=chr(0x80 | $c>>6 & 0x3F);
      $str.=chr(0x80 | $c & 0x3F);
  } else if ($c < 0x200000) {
      $str.=chr(0xF0 | $c>>18);
      $str.=chr(0x80 | $c>>12 & 0x3F);
      $str.=chr(0x80 | $c>>6 & 0x3F);
      $str.=chr(0x80 | $c & 0x3F);
  }
  return iconv('UTF-8', 'GB2312', $str);
}
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.{4};|&#\d+;|.+/U",$str,$r);
$ar = $r[0];
print_r($ar);
foreach($ar as $k=>$v) {
  if(substr($v,0,2) == "%u")
    $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,-4)));
  elseif(substr($v,0,3) == "")
    $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,3,-1)));
  elseif(substr($v,0,2) == "&#") {
echo substr($v,2,-1)."<br>";
    $ar[$k] = iconv("UCS-2","GB2312",pack("n",substr($v,2,-1)));
  }
}
return join(" ",$ar);
}
//下面是转换功能
$db = mysql_connect("localhost", "dbname", "password");
mysql_select_db("dbname",$db);
$result = mysql_query("SELECT * FROM dede_archives",$db);
if ($result === false) die("failed");
while ($fields = mysql_fetch_row($result)) {
        $con=$fields[10];
        $con = iconv("UTF-8","GB2312",$con);//主要是iconv函数的使用
        $update="update dede_archives set title='".$con."' where ID=".$fields[0];
        //echo $update;
        mysql_query($update);
        echo $fields[0]."OK"."<br />";
}
?>

posted @ 2007-04-16 19:38 吴涛涛 阅读(1601) | 评论 (0)编辑 收藏

最近在研究CMS,在数据转换的时候需要用到mysql的replace函数,这里简单介绍一下!

比如你要将 表 tb1里面的 f1字段的abc替换为def

UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');

REPLACE(str,from_str,to_str)   
在字符串   str   中所有出现的字符串   from_str   均被   to_str替换,然后返回这个字符串:   
mysql>   SELECT   REPLACE('www.mysql.com',   'w',   'Ww'); 
                  ->   'WwWwWw.mysql.com' 
这个函数是多字节安全的。

示例:
UPDATE  `dede_addonarticle`  SET body =  REPLACE ( body,
 '</td>',
 '' );
UPDATE  `dede_addonarticle`  SET body =  REPLACE ( body,
 '</tr>',
 '' );
UPDATE  `dede_addonarticle`  SET body =  REPLACE ( body,
 '<tr>',
 '' );      
UPDATE  `dede_archives`  SET title=  REPLACE ( title,
 '大洋新闻 - ',
 '' ); 
UPDATE  `dede_addonarticle`  SET body =  REPLACE ( body,
 '../../../../../../',
 'http://special.dayoo.com/meal/' );

mysql replace

用法1.replace intoreplace into table (id,name) values(‘1‘,‘aa‘),(‘2‘,‘bb‘)
此语句的作用是向表table中插入两条记录。
2.replace(object, search,replace)
把object中出现search的全部替换为replaceselect replace(‘www.163.com‘,‘w‘,‘Ww‘)--->WwW wWw.163.com

例:把表table中的name字段中的 aa替换为bbupdate table set name=replace(name,‘aa‘,‘bb‘)

posted @ 2007-04-13 16:03 吴涛涛 阅读(80976) | 评论 (6)编辑 收藏