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 8481681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:37:25+00:00 2026-06-10T19:37:25+00:00

I wrote a program in PHP to find and print all links present on

  • 0

I wrote a program in PHP to find and print all links present on a web page. It also goes inside any links it found and does the same. My problem is that in some sites (like Youtube) it won’t print the links, or follow inside them.

Here is my main code:

function echo_urls($site_address){

    if(check_valid_url($site_address)){
        $site = new site();
        $site->address = $site_address;
        $site->full_address = "<a href=\"$site_address\">$site_address</a>";
        $site->depth = 0;

        $queue = new queue();

        $queue->push($site);
        array_push($queue->seen,$site->address);

        $depth = 0;

        while(($site = $queue->get_first())){
            $depth++;
            echo $site->depth." : ".$site->full_address."<br>";
            $queue = push_links($site->address,$queue,$depth);
        }
    }
    else;
}
function push_links($site_address,$queue,$depth){
if($depth<4){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$site_address);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        $result=curl_exec ($ch);
        curl_close ($ch);

        if( $result ){
            preg_match_all( '/<a\s[^>]*href=([\"\']??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU', $result, $list);

            $list = $list[0];

            foreach( $list as $item ) {
                if(!(empty($item)))
                if($result = get_all_string_between($item,"href=\"","\"")){
                    if((array_search($result[0],$queue->seen))==false){
                        $site = new site();
                        $site->address = $result[0];
                        $site->full_address = $item;
                        $site->depth = $depth;
                        $queue->push($site);
                        array_push($queue->seen,$site->address);
                    }
                }
            }
        }
    }

    return $queue;
}
  • 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-06-10T19:37:26+00:00Added an answer on June 10, 2026 at 7:37 pm

    It’s hard to tell by looking at a couple of functions, but my guess is:

    1. YouTube is blocking you
    2. This part if($depth<4){ is stopping push_links from executing because it might be returning FALSE

    Also, don’t use RegEx for this. Use something like The DOMDocument class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a program in PHP to find the largest prime factor. I think
I wrote a web based program using PHP, HTML, CSS and MySQL database. I
I wrote a program for downloading an image from web using AsyncTask in service
I wrote a PHP program that hooks into syslog-ng (via syslog-ng.conf ) and it's
I am new to PHP, just downloaded it, and wrote a Hello, World! program:
I just start coding in PHP, i wrote my first php + mysql program
There's a program called getID3 (written in php) that copies all the id3 tags
I wrote a facebook php program to post in 10 friends wall. But If
I wonder when we write a program in PHP, Ruby, or Python, how do
I am trying to write a program in PHP which I had already written

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.