Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-07 11:42:00
Original
1271 people have browsed it

根据当前页面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元

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!