php code problem


getlink.html

// all other basic html tags are here which is not need to understand this like(head,body etc)
This is the website NO # 1
This is google site

<?php $file = file_get_contents('getlink.html'); $matches = preg_match_all('/]*)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'.'
'; } else { echo 'False'.'
'; } } ?>

when i m run it it returns both time false insided of one time false and second time true for
both two links bcs second link match with $test[1].if i remove the first link then it returns
true.Please tell me about this i m really worried about this.
plz plz help me.
…thanks…

Well, normally this line:
foreach($match[1] as $links) {

would be more like this:
foreach($match as $links) {

The first way always takes just the second entry in $match and ALWAYS will take just that item.
The second version takes all of the items in the $match array and passes them one at a time to the
commands after the foreach…

Also, in the for loop, you are comparing $match[1] array which will always be the same item, not the link as it should be. With your foreach, you pull each value from the $match array and use the data by name of $links. Therefore, you should be testing for $links not $match. Something like: If ($links[1]==$test[1]) …

Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service