代码如下 | 复制代码 |
<script language="JavaScript" type="text/网页特效">
$sql="select * from ptypes where sid = 0 and ssid =0"; <select name="province" id="province" onchange="if(this.value != '') setCity(this.options[this.selectedIndex].value);"> <select name="ssid" id="ssid"> |
代码如下 | 复制代码 |
$path = '..'; function get_filetree($path){ $tree = array(); foreach(glob($path.'/*') as $single){ if(is_dir($single)){ $tree = array_merge($tree,get_filetree($single)); } else{ $tree[] = $single; } } return $tree; } print_r(get_filetree($path)); |
<html>
<head>
<title>无刷新上传文件</title>
<meta Content-type="text/html" charset="utf-8" />
<script type="text/网页特效">
function startUpload() {
document.getElementById('processing').innerHTML = 'loding...';
return true;
}
function stopUpload(rel){
var msg;
switch (rel) {
case 0:
msg = "上传成功";
break;
case 1:
msg = "上传的文件超过限制";
break;
case 2:
msg = "只能上传图片文件";
break;
default:
msg = "上传文件失败";
}
document.getElementById('processing').innerHTML = msg;
}
</script>
</head>
<body>
<div style="text-align:center">
<div id="processing"></div>
<form action="upload.php教程" method="post" enctype="multipart/form-data" target="form-target" onsubmit="startUpload();">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="file" name="myfile" />
<input type="submit" name="sub" value="upload" />
</form>
<iframe style="width:0; height:0; border:0;" name="form-target"></iframe>
</div>
</body>
</html>
php代码
里面有各种大家开发中常用到的种编码如uft8->gbk gbk转utf8 繁体转简体 简体转繁体 utf8转unicode gbk转拼音 Ascii转拼音 等<?php
sleep(2);
$fileTypes = array('jpg','png','gif','bmp');
$result = null;
$uploadDir = './upfiles';
$maxSize = 1 * pow(2,20);
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['sub'])) {
$myfile = $_FILES['myfile'];
$myfileType = substr($myfile['name'], strrpos($myfile['name'], ".") + 1);
if ($myfile['size'] > $maxSize) {
$result = 1;
} else if (!in_array($myfileType, $fileTypes)) {
$result = 2;
} elseif (is_uploaded_file($myfile['tmp_name'])) {
$toFile = $uploadDir . '/' . $myfile['name'];
if (@move_uploaded_file($myfile['tmp_name'], $toFile)) {
$result = 0;
} else {
$result = -1;
}
} else {
$result = 1;
}
}
?>
<script type="text/javascript">
window.top.window.stopUpload(<?php echo $result; ?>);
</script>
里面有各种大家开发中常用到的种编码如uft8->gbk gbk转utf8 繁体转简体 简体转繁体 utf8转unicode gbk转拼音 Ascii转拼音 等
<?php教程
/**
* utf8转gbk
* @param $utfstr
*/
function utf8_to_gbk($utfstr) {
global $UC2GBTABLE;
$okstr = '';
if(empty($UC2GBTABLE)) {
$filename = CODETABLEDIR.'gb-unicode.table';
$fp = fopen($filename, 'rb');
while($l = fgets($fp,15)) {
$UC2GBTABLE[hexdec(substr($l, 7, 6))] = hexdec(substr($l, 0, 6));
}
fclose($fp);
}
$okstr = '';
$ulen = strlen($utfstr);
for($i=0; $i<$ulen; $i++) {
$c = $utfstr[$i];
$cb = decbin(ord($utfstr[$i]));
if(strlen($cb)==8) {
$csize = strpos(decbin(ord($cb)),'0');
for($j = 0; $j < $csize; $j++) {
$i++;
$c .= $utfstr[$i];
}
$c = utf8_to_unicode($c);
if(isset($UC2GBTABLE[$c])) {
$c = dechex($UC2GBTABLE[$c]+0x8080);
$okstr .= chr(hexdec($c[0].$c[1])).chr(hexdec($c[2].$c[3]));
} else {
$okstr .= '&#'.$c.';';
}
} else {
$okstr .= $c;
}
}
$okstr = trim($okstr);
return $okstr;
}
/**
* gbk转utf8
* @param $gbstr
*/
function gbk_to_utf8($gbstr) {
global $CODETABLE;
if(empty($CODETABLE)) {
$filename = CODETABLEDIR.'gb-unicode.table';
$fp = fopen($filename, 'rb');
while($l = fgets($fp,15)) {
$CODETABLE[hexdec(substr($l, 0, 6))] = substr($l, 7, 6);
}
fclose($fp);
}
$ret = '';
$utf8 = '';
while($gbstr) {
if(ord(substr($gbstr, 0, 1)) > 0x80) {
$thisW = substr($gbstr, 0, 2);
$gbstr = substr($gbstr, 2, strlen($gbstr));
$utf8 = '';
@$utf8 = unicode_to_utf8(hexdec($CODETABLE[hexdec(bin2hex($thisW)) - 0x8080]));
if($utf8 != '') {
for($i = 0; $i < strlen($utf8); $i += 3) $ret .= chr(substr($utf8, $i, 3));
}
} else {
$ret .= substr($gbstr, 0, 1);
$gbstr = substr($gbstr, 1, strlen($gbstr));
}
}
return $ret;
}
/**
* 繁体转简体
* @param $Text
*/
function big5_to_gbk($Text) {
global $BIG5_DATA;
if(empty($BIG5_DATA)) {
$filename = CODETABLEDIR.'big5-gb.table';
$fp = fopen($filename, 'rb');
$BIG5_DATA = fread($fp, filesize($filename));
fclose($fp);
}
$max = strlen($Text)-1;
for($i = 0; $i < $max; $i++) {
$h = ord($Text[$i]);
if($h >= 0x80) {
$l = ord($Text[$i+1]);
if($h==161 && $l==64) {
$gbstr = ' ';
} else {
$p = ($h-160)*510+($l-1)*2;
$gbstr = $BIG5_DATA[$p].$BIG5_DATA[$p+1];
}
$Text[$i] = $gbstr[0];
$Text[$i+1] = $gbstr[1];
$i++;
}
}
return $Text;
}
/**
* 简体转繁体
* @param $Text
*/
function gbk_to_big5($Text) {
global $GB_DATA;
if(empty($GB_DATA)) {
$filename = CODETABLEDIR.'gb-big5.table';
$fp = fopen($filename, 'rb');
$gb = fread($fp, filesize($filename));
fclose($fp);
}
$max = strlen($Text)-1;
for($i = 0; $i < $max; $i++) {
$h = ord($Text[$i]);
if($h >= 0x80) {
$l = ord($Text[$i+1]);
if($h==161 && $l==64) {
$big = ' ';
} else {
$p = ($h-160)*510+($l-1)*2;
$big = $GB_DATA[$p].$GB_DATA[$p+1];
}
$Text[$i] = $big[0];
$Text[$i+1] = $big[1];
$i++;
}
}
return $Text;
}
/**
* unicode转utf8
* @param $c
*/
function unicode_to_utf8($c) {
$str = '';
if($c < 0x80) {
$str .= $c;
} elseif($c < 0x800) {
$str .= (0xC0 | $c >> 6);
$str .= (0x80 | $c & 0x3F);
} elseif($c < 0x10000) {
$str .= (0xE0 | $c >> 12);
$str .= (0x80 | $c >> 6 & 0x3F);
$str .= (0x80 | $c & 0x3F);
} elseif($c < 0x200000) {
$str .= (0xF0 | $c >> 18);
$str .= (0x80 | $c >> 12 & 0x3F);
$str .= (0x80 | $c >> 6 & 0x3F);
$str .= (0x80 | $c & 0x3F);
}
return $str;
}
/**
* utf8转unicode
* @param $c
*/
function utf8_to_unicode($c) {
switch(strlen($c)) {
case 1:
return ord($c);
case 2:
$n = (ord($c[0]) & 0x3f) << 6;
$n += ord($c[1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$n = (ord($c[0]) & 0x0f) << 18;
$n += (ord($c[1]) & 0x3f) << 12;
$n += (ord($c[2]) & 0x3f) << 6;
$n += ord($c[3]) & 0x3f;
return $n;
}
}/**
* Ascii转拼音
* @param $asc
* @param $pyarr
*/
function asc_to_pinyin($asc,&$pyarr) {
if($asc < 128)return chr($asc);
elseif(isset($pyarr[$asc]))return $pyarr[$asc];
else {
foreach($pyarr as $id => $p) {
if($id >= $asc)return $p;
}
}
}
/**
* gbk转拼音
* @param $txt
*/
function gbk_to_pinyin($txt) {
if(CHARSET != 'gbk') {
$txt = iconv(CHARSET,'GBK',$txt);
}
$l = strlen($txt);
$i = 0;
$pyarr = array();
$py = array();
$filename = CODETABLEDIR.'gb-pinyin.table';
$fp = fopen($filename,'r');
while(!feof($fp)) {
$p = explode("-",fgets($fp,32));
$pyarr[intval($p[1])] = trim($p[0]);
}
fclose($fp);
ksort($pyarr);
while($i<$l) {
$tmp = ord($txt[$i]);
if($tmp>=128) {
$asc = abs($tmp*256+ord($txt[$i+1])-65536);
$i = $i+1;
} else $asc = $tmp;
$py[] = asc_to_pinyin($asc,$pyarr);
$i++;
}
return $py;
}
?>
下面举了二个实现来告诉你如何过滤重复的内容,有需要的朋友可以参考
foreach($arr as $value){
if(!empty($value)){
$strs=strstr($value,"新闻");
}
}
输出:新闻 新闻
直接用array_unique 函数就可以了。
$string= '数组aabbccdd';
function str_split_utf8($str) {
$split=1;
$array = array();
for ( $i=0; $i < strlen( $str ); ){
$value = ord($str[$i]);
if($value > 127){
if($value >= 192 && $value <= 223)
$split=2;
elseif($value >= 224 && $value <= 239)
$split=3;
elseif($value >= 240 && $value <= 247)
$split=4;
}else{
$split=1;
}
$key = NULL;
for ( $j = 0; $j < $split; $j++, $i++ ) {
$key .= $str[$i];
}
array_push( $array, $key );
}
return $array;
}
print_r(array_unique(str_split_utf8($string)));
这里有篇参考文章
php教程er/21/899e11a21ae817a97d3ce64f851ab9f6.htm">http://www.111cn.net/phper/21/899e11a21ae817a97d3ce64f851ab9f6.htm