获取链接.html
// all other basic html tags are here which is not need to understand this like(head,body etc)
<a href="website.html">This is the website NO # 1</a>
<a href="http://www.google.com/">This is google site</a>
PHP
<?php
$file = file_get_contents('getlink.html');
$matches = preg_match_all('/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^<]*)<\/a>/is'
,$file,$match); // work fine
$test1 = preg_match_all('/href=\"((?:https?|ftp)\:\/\/\w+\.[\w-]+\..+)\"/i'
,$file,$test); // work fine
foreach($match[1] as $links) {
if ($match[1] == $test[1]){ // write $match[1] not $links
// bcs $links does not work
echo 'True'.'<br />';
} else {
echo 'False'.'<br />';
}
}
?>
当我运行它时,它会返回false
两次,而不是一次false
和第二次true
。
第二个链接应该与$test[1]
. 如果我删除第一个链接,它会返回true
,
请帮帮我,我真的很担心。