首頁 >php教程 >php手册 >U函数,正常人版本

U函数,正常人版本

WBOY
WBOY原創
2016-06-07 11:41:181357瀏覽

tp自己的U函数太反人类了,把参数都伪静态,其实造成了极大的不兼容。很多cdn,rpc,浏览器,http协议,反向代理等应用会对此理解失误,具体的问题我说不上来,反正我觉得这种伪装成无数个文件的方法太煞笔了,文件就是文件,参数就是参数,把参数伪装成文件算是怎么回事啊!!!!太反人类了,完全不能忍
/**<br>  * URL组装 支持不同URL模式<br>  * @param string $url URL表达式,格式:'[模块/控制器/操作#锚点@域名]?参数1=值1&参数2=值2...'<br>  * @param string|array $vars 传入的参数,支持数组和字符串<br>  * @param string $suffix 伪静态后缀,默认为true表示获取配置值<br>  * @param boolean $domain 是否显示域名<br>  * @return string<br>  */<br> function U($url='',$vars='',$suffix=true,$domain=false) {<br>     // 解析URL<br>     $info   =  parse_url($url);<br>     $url    =  !empty($info['path'])?$info['path']:ACTION_NAME;<br>     if(isset($info['fragment'])) { // 解析锚点<br>         $anchor =   $info['fragment'];<br>         if(false !== strpos($anchor,'?')) { // 解析参数<br>             list($anchor,$info['query']) = explode('?',$anchor,2);<br>         }        <br>         if(false !== strpos($anchor,'@')) { // 解析域名<br>             list($anchor,$host)    =   explode('@',$anchor, 2);<br>         }<br>     }elseif(false !== strpos($url,'@')) { // 解析域名<br>         list($url,$host)    =   explode('@',$info['path'], 2);<br>     }<br>     // 解析子域名<br>     if(isset($host)) {<br>         $domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.'));<br>     }elseif($domain===true){<br>         $domain = $_SERVER['HTTP_HOST'];<br>         if(C('APP_SUB_DOMAIN_DEPLOY') ) { // 开启子域名部署<br>             $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.');<br>             // '子域名'=>array('模块[/控制器]');<br>             foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) {<br>                 $rule   =   is_array($rule)?$rule[0]:$rule;<br>                 if(false === strpos($key,'*') && 0=== strpos($url,$rule)) {<br>                     $domain = $key.strstr($domain,'.'); // 生成对应子域名<br>                     $url    =  substr_replace($url,'',0,strlen($rule));<br>                     break;<br>                 }<br>             }<br>         }<br>     }<br> <br>     // 解析参数<br>     if(is_string($vars)) { // aaa=1&bbb=2 转换成数组<br>         parse_str($vars,$vars);<br>     }elseif(!is_array($vars)){<br>         $vars = array();<br>     }<br>     if(isset($info['query'])) { // 解析地址里面参数 合并到vars<br>         parse_str($info['query'],$params);<br>         $vars = array_merge($params,$vars);<br>     }<br>     <br>     // URL组装<br>     $depr       =   C('URL_PATHINFO_DEPR');<br>     $urlCase    =   C('URL_CASE_INSENSITIVE');<br>     if($url) {<br>         if(0=== strpos($url,'/')) {// 定义路由<br>             $route      =   true;<br>             $url        =   substr($url,1);<br>             if('/' != $depr) {<br>                 $url    =   str_replace('/',$depr,$url);<br>             }<br>         }else{<br>             if('/' != $depr) { // 安全替换<br>                 $url    =   str_replace('/',$depr,$url);<br>             }<br>             // 解析模块、控制器和操作<br>             $url        =   trim($url,$depr);<br>             $path       =   explode($depr,$url);<br>             $var        =   array();<br>             $varModule      =   C('VAR_MODULE');<br>             $varController  =   C('VAR_CONTROLLER');<br>             $varAction      =   C('VAR_ACTION');<br>             $var[$varAction]       =   !empty($path)?array_pop($path):ACTION_NAME;<br>             $var[$varController]   =   !empty($path)?array_pop($path):CONTROLLER_NAME;<br>             if($maps = C('URL_ACTION_MAP')) {<br>                 if(isset($maps[strtolower($var[$varController])])) {<br>                     $maps    =   $maps[strtolower($var[$varController])];<br>                     if($action = array_search(strtolower($var[$varAction]),$maps)){<br>                         $var[$varAction] = $action;<br>                     }<br>                 }<br>             }<br>             if($maps = C('URL_CONTROLLER_MAP')) {<br>                 if($controller = array_search(strtolower($var[$varController]),$maps)){<br>                     $var[$varController] = $controller;<br>                 }<br>             }<br>             if($urlCase) {<br>                 $var[$varController]   =   parse_name($var[$varController]);<br>             }<br>             $module =   '';<br>             <br>             if(!empty($path)) {<br>                 $var[$varModule]    =   array_pop($path);<br>             }else{<br>                 if(C('MULTI_MODULE')) {<br>                     if(MODULE_NAME != C('DEFAULT_MODULE') || !C('MODULE_ALLOW_LIST')){<br>                         $var[$varModule]=   MODULE_NAME;<br>                     }<br>                 }<br>             }<br>             if($maps = C('URL_MODULE_MAP')) {<br>                 if($_module = array_search(strtolower($var[$varModule]),$maps)){<br>                     $var[$varModule] = $_module;<br>                 }<br>             }<br>             if(isset($var[$varModule])){<br>                 $module =   $var[$varModule];<br>                 unset($var[$varModule]);<br>             }<br>             <br>         }<br>     }<br> <br>     if(C('URL_MODEL') == 0) { // 普通模式URL转换<br>         $url        =   __APP__.'?'.C('VAR_MODULE')."={$module}&".http_build_query(array_reverse($var));<br>         if($urlCase){<br>             $url    =   strtolower($url);<br>         }        <br>         if(!empty($vars)) {<br>             $vars   =   http_build_query($vars);<br>             $url   .=   '&'.$vars;<br>         }<br>     }else{ // PATHINFO模式或者兼容URL模式<br>         if(isset($route)) {<br>             $url    =   __APP__.'/'.rtrim($url,$depr);<br>         }else{<br>             $module =   defined('BIND_MODULE') ? '' : $module;<br>             $url    =   __APP__.'/'.($module?$module.MODULE_PATHINFO_DEPR:'').implode($depr,array_reverse($var));<br>         }<br>         if($urlCase){<br>             $url    =   strtolower($url);<br>         }<br>         /*<br>         if(!empty($vars)) { // 添加参数<br>             foreach ($vars as $var => $val){<br>                 if('' !== trim($val))   $url .= $depr . $var . $depr . urlencode($val);<br>             }                <br>         }<br>         */<br>         if($suffix) {<br>             $suffix   =  $suffix===true?C('URL_HTML_SUFFIX'):$suffix;<br>             if($pos = strpos($suffix, '|')){<br>                 $suffix = substr($suffix, 0, $pos);<br>             }<br>             if($suffix && '/' != substr($url,-1)){<br>                 $url  .=  '.'.ltrim($suffix,'.');<br>             }<br>             /*修改处*/<br>             if(!empty($vars)) {<br>                 $vars   =   http_build_query($vars);<br>                 $url   .=   '?'.$vars;<br>             }<br>         }<br>     }<br>     if(isset($anchor)){<br>         $url  .= '#'.$anchor;<br>     }<br>     if($domain) {<br>         $url   =  (is_ssl()?'https://':'http://').$domain.$url;<br>     }<br>     return $url;<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn