脚本宝典收集整理的这篇文章主要介绍了如何使用PHP检查URL是外部URL还是内部URL?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
foreach($htML->find('a[href!="#"]') as $ahref) { $ahrefs++; }
我想做这样的事情:
foreach($html->find('a[href!="#"]') as $ahref) { if(isexternal($ahref)) { $externaL++; } $ahrefs++; }
function isexternal($url) { // FOO... // test if link is internal/external if(/*condITion is true*/) { return true; } else { return false; } }
救命!
function isexternal($url) { $components = parse_url($url); return !empty($components['host']) && strcasecmp($components['host'],'example.COM'); // empty host will indicate url like '/relative.PHP' }
Hovewer这将把www.example.com和example.com视为不同的主机.如果您希望将所有子域都视为本地链接,那么该函数将会更大一些:
function isexternal($url) { $components = parse_url($url); if ( empty($components['host']) ) return false; // we will treat url like '/relative.PHP' as relative if ( strcasecmp($components['host'],'example.com') === 0 ) return false; // url host looks exactly like the local host return strrpos(strtolower($components['host']),'.example.com') !== strlen($components['host']) - strlen('.example.com'); // check if the url host is a subdomain }
以上是脚本宝典为你收集整理的如何使用PHP检查URL是外部URL还是内部URL?全部内容,希望文章能够帮你解决如何使用PHP检查URL是外部URL还是内部URL?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。