getlink.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 />';
}
}
?>
実行すると、1回と2false
回ではなく、両方の時間が返されます。false
true
2 番目のリンクは と一致する必要があり$test[1]
ます。最初のリンクを削除すると、 が返さtrue
れます。
助けてください、本当に心配です。