Jump to content

[SOLVED] using substr_count - problem


DJphp

Recommended Posts

 

I have a script that scrapes a web page for URL's.

 

 

preg_match_all($urlpatternLink, $data, $matchesLink);

foreach ($matchesLink[1] as $u) {

  echo $u;

}

 

 

 

The output looks like:

showthread.php?s=49432320845584ac41dadf97ecf4db95&t=26149

showthread.php?s=49432320845584ac41dadf97ecf4db95&t=26149&page=2

showthread.php?s=49432320845584ac41dadf97ecf4db95&p=274948#post274948

 

I do not want to print out the lines that contain "&p", that is, similar to the last two lines ('&p' is found in '&p=' and '&page').

So, I tried to use "substr_count" as below:

 

 

$unwantedLink1 = "&p";

preg_match_all($urlpatternLink, $data, $matchesLink);

foreach ($matchesLink[1] as $u) {

  $matchUnwantedLinkCount = substr_count($u, $unwantedLink1);

  echo $matchUnwantedLinkCount;

  if ( $matchUnwantedLinkCount == 0 ) {

      $urlLink = $u;

}

  echo $urlLink;

}

 

 

Unfortunately, $matchUnwantedLinkCount  is always 0, which means that the output is the same as earlier, that is, all results are displayed, not just those that do not contain "&p".

 

Any help would be appreciated in using substr_count, or doing what I need.

 

thanks,

DJphp

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/78751-solved-using-substr_count-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.