首页 > 编程技术 > php

php url地址栏传中文值乱码问题与解决方法

发布时间:2016-11-25 15:55

 代码如下 复制代码

$url = 'aaa.php?region='.urldecode("四川省");

?>
<a href="<?php echo $url;?>">aaa </a>

//方法二base64_encode

<?
$test="四川省";
$test1=base64_encode($test);
echo '<a href="www.111cn.net?region=$test1">aaa </a>';
?>

另一页面使用base64_decode解开

base64_decode($region);

//方法三让服务器支持中文

[root@dhcp ~]# locale

lang=zh_cn.utf-8
lc_ctype="zh_cn.utf-8"
lc_numeric="zh_cn.utf-8"
lc_time=c
lc_collate=c
lc_monetary="zh_cn.utf-8"
lc_messages="zh_cn.utf-8"
lc_paper="zh_cn.utf-8"
lc_name="zh_cn.utf-8"
lc_address="zh_cn.utf-8"
lc_telephone="zh_cn.utf-8"
lc_measurement="zh_cn.utf-8"
lc_identification="zh_cn.utf-8"
lc_all=
[root@dhcp ~]#

 

 代码如下 复制代码
$dirs    = array();
foreach(glob("test/*") as $d)
{
    if(is_dir($d))
    {
        $dirs[]    = $d;
    }
}
print_r($dirs);

//方法二

 代码如下 复制代码
glob("test/*", glob_onlydir) ;

//查找目录下所有文件

 代码如下 复制代码
function listdir($dir){
if(is_dir($dir)){
if ($dh = opendir($dir)) {
while (($file= readdir($dh)) !== false){
if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){
echo "<b><font color='red'>文件名:</font></b>",$file,"<br><hr>";
listdir($dir."/".$file."/");
}else{
if($file!="." && $file!=".."){
echo $file."<br>";
}
}
}
closedir($dh);
}
}
}
//开始运行
listdir("e:/www.111cn.net/");


?>

 代码如下 复制代码
$sn = strtolower($_server['server_name']?$_server['server_name']:$_server['http_host']);
$query = trim(@$_server['request_uri']);
$sn = str_replace('http://','',strtolower($sn));
$url ='www.111cn.net';
if( $sn !=$url || strpos($query,'index.php'))
{
 header( "http/1.1 301 moved permanently" );
 header( "location: http://$url" );
}

//带参数

 代码如下 复制代码

$url = "http://".$url.$_server["request_uri"];
header("http/1.1 301 moved permanently");
header ("location:http://$url");

 代码如下 复制代码

$v = array('vv','bb');
$str = "vv,cc,abcde,www.111cn.net,vv";
$str=preg_replace("/$v[0]/","<a href=".$v[1]." target=_blank >".$v[0]."</a>",$str,1);
echo $str;
//bb,cc,abcde,www.111cn.net,vv

$str=preg_replace("/$v[0]/","<a href=".$v[1]." target=_blank >".$v[0]."</a>",$str,2);
//bb,cc,abcde,www.111cn.net,bb

//方法一模仿用户访问网页

 代码如下 复制代码
function readpr($link,$url)
{
 $fp = fsockopen ($url, 80, $errno, $errstr, 30);
 if (!$fp)
 {
  echo "$errstr ($errno) ";
  exit(1);
 }
 else
 {
  $out = "get $link http/1.0 ";
  $out .= "host: $url ";
  $out .= "user-agent: mozilla/4.0 (compatible; googletoolbar 2.0.114.9-big; linux 2.6) ";
  $out .= "connection: close ";
  fwrite($fp, $out);
  do{
  $line = fgets($fp, 128);
  }while ($line !== " ");
  $data = fread($fp,8192);
  fclose ($fp);
  return $data;
 }
}

//方法二用curl_init读取远程网页内容

 代码如下 复制代码

function init()
{
  $ch = curl_init();
  curl_setopt ($ch, curlopt_url, $url);
  curl_setopt ($ch, curlopt_returntransfer, 1);
  curl_setopt ($ch, curlopt_connecttimeout, $timeout);
  $file_contents = curl_exec($ch);
  curl_close($ch);
}
//方法三最简单的用file_get_contents

function getfiles($value)
{
 $get_file = @file_get_contents($value);
}
//方法四用fopen采集远程网页内容

function getfiles($value)
{
 return fopen($value);
}

标签:[!--infotagslink--]

您可能感兴趣的文章: