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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.