PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm reading an HTML document into $html using fread(). I know this is working, because the $html var I have checked to contain the code of this page. I also know it contains the string,
while( $row = mysql_fetch_array( $result ) )
{
$fp = fopen( $row['TargettedLinkReciprocalURL'], 'r' );
// Assume HTML won't be more than 30K, otherwise chances are there's too many links
// on the page to be worth it anyway
$html = fread( $fp, 30000 );
if( preg_match( '/www\.spanish-property-partnership\.biz/', $html, $matches, 'i' ) == 0 )
{
// Remove link
echo 'Link remove: '.$row['TargettedLinkURL'];
}
else
{
echo 'Link left alone - present';
}
fclose( $fp );
}
I know that $html is populated properly as I've echo'd it. I've tried using escape for '-' but it still doesn't seem to work. I also know it's all read into $html as it is less than 30K in size.
Right, so does someone care to put my lazy, unlearning, forum undisciplined ass to account and tell me what is wrong with this regex? I've been amazed over the last few days the pompousness of some members of this forum in answer to some pretty basic queries - we've got the usual Forum/Totalitarian state mentality occurring here, which is a shame because this is one of the few forums where I haven't seen it before.
while($row = mysql_fetch_assoc($result))
{
$fp = fopen( $row['TargettedLinkReciprocalURL'], 'r' );
// Assume HTML won't be more than 30K, otherwise chances are there's too many links
// on the page to be worth it anyway
$html = fread( $fp, 30000 );
if (preg_match('/www\.spanish-property-partnership\.biz/', $html))//matches found so remove link
{
// Remove link
echo 'Link remove: '.$row['TargettedLinkURL'];
}
else//no matches found for that url so leave the link alone
{
echo 'Link left alone - present';
}
fclose( $fp );
}
$string = '1234567 Words 89';
preg_match('/[a-z]+/i', $string, $matches);
print_r($matches);
My mistake sorry. This is even clearly mentionned in the php manual too... (After a first glance, i couldn't find it in the PCRE manual...)
If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
A bit further in that manual i also read:
preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match
So, in the case something is matched, preg_match returns something != 0
This explains why the == 0 branch is not executed.