Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7487903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:41:09+00:00 2026-05-29T14:41:09+00:00

I have this script. I need is so that it only writes the links

  • 0

I have this script.
I need is so that it only writes the links that contain "/product-product/" to the file items.txt. Well, not the wohle link but the 10 didget item-nr
product-product/1007687980

In the example you see the item-nr is something with /100. I was searching for items in a category where the nrs are something with /100. But that is no longer needed.

$keyword= $_SERVER['QUERY_STRING'];
$site=1;
while ($site<30) {
$content = file_get_contents('http://www.example.com/?keywords='. $keyword .'&x=0&y=0&pagecount='.$site.'&sort=sort');
$html = $content;
$dom = new DomDocument();
@$dom->loadHTML($html);
$urls = $dom->getElementsByTagName('a');

$lookfor='http://www.example.com';

foreach ($urls as $url){
    if(substr($url->getAttribute('href'),0,strlen($lookfor))==$lookfor){
       $tubeurl = str_replace ("http://www.example.com","",$url->getAttribute('href'));
    $tubeurl = substr($tubeurl, strpos($tubeurl,"/product-product/100")+17, 10);
    file_put_contents("items.txt", "" .$tubeurl. "
", FILE_APPEND | LOCK_EX);// this line must remain, it makes it so that there is a new line  \n wouldn't work

    }
} $site++; echo $site;}

regex would be a solution. but I read here on Stackoverflow that is a lot of work for the server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:41:13+00:00Added an answer on May 29, 2026 at 2:41 pm

    A simple regular expression that puts your product ID into $1 should do the trick. You probably want some more logic to make sure that $1. Modified it so that $1 should always be 10 digits.

    $keyword= $_SERVER['QUERY_STRING'];
    $site=1;
    while ($site<30) {
      $content = file_get_contents('http://www.domain.com/?keywords=' . $keyword . '&x=0&y=0&pagecount='.$site.'&sort=sort');
      $html = $content;
      $dom = new DomDocument();
      @$dom->loadHTML($html);
      $urls = $dom->getElementsByTagName('a');
    
      $lookfor='http://www.domain.com';
    
      foreach ($urls as $url){
          if(substr($url->getAttribute('href'),0,strlen($lookfor))==$lookfor){
             $tubeurl = str_replace ("http://www.domain.com","",$url->getAttribute('href'));
    
             preg_match("/^http.*/product-product\/(\d{10})$/", $tubeurl, $matches);
    
    
    
          file_put_contents("items.txt", $1,
            FILE_APPEND | LOCK_EX); // this line must remain, it makes it so that there is a new line  \n wouldn't work
    
          }
      } 
    
      $site++;
    
      echo $site;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script with infinite loop. I need this script running forever.
I have this script to generate an XML file for an RSS feed. Works
I have a PHP script that reads and writes from multiple databases. I am
I have a large filesystem that I need to traverse for errors. Each file
I have a Python script that writes data packets to an Arduino board through
This is a bit confusing. I have a linux executable that I do not
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
I have this script which basically toggles a bgColor class on and off so
i have this script $content = string if(!isset($_GET['page'])){ $page = 1; } else{ $page
I have this script and when i try to run it, it just says

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.