Home  >  Article  >  php教程  >  根据当前页面url进行地址补全(采集用)

根据当前页面url进行地址补全(采集用)

WBOY
WBOYOriginal
2016-06-07 11:42:001272browse

根据当前页面url进行地址补全(采集用)
function formaturl($url, $str){<br>     if (is_array($str)) {<br>         $return = array();<br>         foreach ($str as $href) {<br>             $return[] = formaturl($url, $href);<br>         }<br>         return $return;<br>     } else {<br>         if (stripos($str, 'http://')===0 || stripos($str, 'ftp://')===0) {<br>             return $str;<br>         }<br>         $str = str_replace('\\', '/', $str);<br>         $parseUrl = parse_url(dirname($url).'/');<br>         $scheme = isset($parseUrl['scheme']) ? $parseUrl['scheme'] : 'http';<br>         $host = $parseUrl['host'];<br>         $path = isset($parseUrl['path']) ? $parseUrl['path'] : '';<br>         $port = isset($parseUrl['port']) ? $parseUrl['port'] : '';<br> <br>         if (strpos($str, '/')===0) {<br>             return $scheme.'://'.$host.$str;<br>         } else {<br>             $part = explode('/', $path);<br>             array_shift($part);<br>             $count = substr_count($str, '../');<br>             if ($count>0) {<br>                 for ($i=0; $i                     array_pop($part);<br>                 }<br>             }<br>             $path = implode('/', $part);<br>             $str = str_replace(array('../','./'), '', $str);<br>             $path = $path=='' ? '/' : '/'.trim($path,'/').'/';<br>             return $scheme.'://'.$host.$path.$str;<br>         }        <br>     }<br> <br> }

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:ThinkPHP 3.2多个模块使用公共LayoutNext article:js导航