Jump to content

Recommended Posts

Use file_get_contents($url) to get the HTML of the website in question.

 

Then loop through that content looking for <a tags. Each time you find an anchor tag, use substr() and strpos() to extract the link.

 

Do this for all links adding each one into an array. Once you've done this, go through each link checking to see whether it is from the domain you're looking for. You can use the parse_url() function to do this or you can use a combination of strpos() and substr()

 

If you need more information on the functions given above please see these links:

 

http://uk2.php.net/substr

http://uk.php.net/strpos

http://uk2.php.net/function.file-get-contents

http://uk3.php.net/function.parse-url

Link to comment
https://forums.phpfreaks.com/topic/147633-extract-url/#findComment-775011
Share on other sites

<?php
$string = '<a href="http://www.abc.com/rand/file.r01"> <a href="http://www.abc.com/rand/file.r02"> <a href="http://www.abc.com/rand/file.r03">';

preg_match_all('~www.abc.com/(.+?)"~is', $string, $matches);

echo "<pre>" . print_r($matches, 1) . "</pre>";

die();
?>

 

Rough example. But should work.

 

Outputs:

Array
(
    [0] => Array
        (
            [0] => www.abc.com/rand/file.r01"
            [1] => www.abc.com/rand/file.r02"
            [2] => www.abc.com/rand/file.r03"
        )

    [1] => Array
        (
            [0] => rand/file.r01
            [1] => rand/file.r02
            [2] => rand/file.r03
        )

)

Link to comment
https://forums.phpfreaks.com/topic/147633-extract-url/#findComment-775125
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.