php解析字符串里所有URL地址的方法

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php解析字符串里所有URL地址的方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP解析字符串里所有URL地址方法分享给大家供大家参考。具体如下:

<PRe class="brush:PHp;"> <>PHP // $htML = the html on the page // $current_url = the full url that the html came From //(only needed for $repath) // $repath = converts ../ and / and // urls to full valid urls function pageLinks($html,$current_url = "",$repath = false){ preg_match_all("/\ 0 && strlen($current_url) > 0){ $pathi = pathinfo($current_url); $dir = $pathi["dirname"]; $base = parse_url($current_url); $splIT_path = explode("/",$dir); $url = ""; foreach($links as $k => $link){ if(preg_match("/^\.\./",$link)){ $total = substr_count($link,"../"); for($i = 0; $i < $total;="" $i++){="" array_pop($split_path);="" }="" $url="implode("/",$split_path)" .="" "/"="" .="" str_replace("../","",$link);="" }elseif(preg_match("/^\/\//",$link)){="" $url="$base["scheme"]" .="" ":"="" .="" $link;="" }elseif(preg_match("/^\/|^.\//",$link)){="" $url="$base["scheme"]" .="" "://"="" .="" $base["host"]="" .="" $link;="" }elseif(preg_match("/^[a-za-z0-9]/",$link)){="" if(preg_match("/^http/",$link)){="" $url="$link;" }else{="" $url="$dir" .="" "/"="" .="" $link;="" }="" }="" $links[$k]="$url;" }="" }="" return="" $links;="" }="" header("content-type:="" text/plain");="" $url="//www.js-code.com" ;="" $html="file_get_contents($url);" gets="" links="" from="" the="" page:="" print_r(pagelinks($html));="" gets="" links="" from="" the="" page="" and="" formats="" them="" to="" a="" full="" valid="" url:="">

脚本宝典总结

以上是脚本宝典为你收集整理的php解析字符串里所有URL地址的方法全部内容,希望文章能够帮你解决php解析字符串里所有URL地址的方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。