Php link exporter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Hmm it still does not list anything...

Code: Select all

$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
Can i insert an array here like

Code: Select all

$search = array("http://rapidshare.com", "http://www.rapidshare.com", "www.rapidshare.com");
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

The_L wrote:Hmm it still does not list anything...

Code: Select all

$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
Can i insert an array here like

Code: Select all

$search = array("http://rapidshare.com", "http://www.rapidshare.com", "www.rapidshare.com");
If you comment out the lines I suggested earlier (the if(strpos($search, $link)) line and its corresponding closing bracket) what result do you get? Without those lines you can manually check the list to make sure it does contain rapidshare links.

To use an array you just need to add another loop inside your existing ones, e.g.

Code: Select all

echo "<h2>Links present on page: ".$urlrun."</h2><br />";
// Loop to pump out the results
echo "<ul>";
// create an array of terms to find
$search = array('.rapidshare.com','http://rapidshare.com');
foreach ($linkarray as $links) {
    foreach($links as $link) {
        // loop through the search terms wit ha foreach
        foreach($search as $search_term) {
            // Comment out the next line to manually check the results
            if(strpos($link, $search_term) > -1) { // Now matching $search_term instead of $search
            // Leave the next line here
                 echo "<li>$link<li>";
            // And comment out the next line
            }
        }
    }
}
echo "</ul>";
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Ok there is something wrong...i commented this line:

Code: Select all

$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
And it does not list anything...:/
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

The_L wrote:Ok there is something wrong...i commented this line:

Code: Select all

$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
And it does not list anything...:/
Why have you commented that line out? You need to comment out the strpos line and its closing bracket, leaving the echo "<li>$link</li>" bit as it is. Everything else stays the same.
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Code: Select all

$linkarray = $tspider->parse_array();
 
echo "<h2>Links present on page: ".$urlrun."</h2><br />";
// Loop to pump out the results
echo "<ul>";
$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
foreach ($linkarray as $links) {
    foreach($links as $link) {
                // if(strpos($link, $search) > -1) {
                    echo "<li>$link<li>";
                // }
    }
}
echo "</ul>";
exit;
There...it still doesnot show anything...
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

Please show the full code again, if its not displaying anything then its likely something at the top has changed something
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Code: Select all

<?php
 
//Make a title spider
$tspider = new tagSpider();
 
//Pass URL to the fetch page function
$tspider->fetchPage($urlrun);
 
// input box
$urlrun = $_POST['urlrun'];
if (!$urlrun) die("<form method='post'><input type='text' name='urlrun'> <input type='submit'></form>");
 
// Enter the tags into the parse array function
$linkarray = $tspider->parse_array();
 
echo "<h2>Links present on page: ".$urlrun."</h2><br />";
// Loop to pump out the results
echo "<ul>";
$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
foreach ($linkarray as $links) {
    foreach($links as $link) {
                // if(strpos($link, $search) > -1) {
                    echo "<li>$link<li>";
                // }
    }
}
echo "</ul>";
exit;
Here is the whole file..
taggrab.rar
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

This bit needs to change

Code: Select all

//Pass URL to the fetch page function
$tspider->fetchPage($urlrun);
 
// input box
$urlrun = $_POST['urlrun'];
if (!$urlrun) die("<form method='post'><input type='text' name='urlrun'> <input type='submit'></form>");
Needs to be the other way around - you have to set $urlrun before you can pass it to fetchPage($urlrun)
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

That makes sence... i done what you told and it listed all links...so i uncommented the codes and its perfect,lists just rapidshare links =))))
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

How can i put the list in <table>? And how to remove those dots per line (in link listing)? So i can middle it and add some graphics...
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

The_L wrote:How can i put the list in <table>? And how to remove those dots per line (in link listing)? So i can middle it and add some graphics...
Replace the <ul> and </ul> tags with <table> and </table> tags. If you want a header row, add something like this straight after the opening <table> tag:

Code: Select all

echo "<tr>
    <th>Col1</th>
    <th>Col2</th>
</tr>";
Then, inside the loop where you currently use echo "<li>$link</li>";, use something like this:

Code: Select all

echo "<tr>
    <td>$link</td>
    <td>something else</td>
</tr>";
That should output each link in its own table row. The <th> ones are table headers, and <td> are table cells.
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Code: Select all

echo "<table align="center">";
$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
foreach ($linkarray as $links) {
    foreach($links as $link) {
                 if(strpos($link, $search) > -1) {
echo "<tr>
    <td>$link</td>
</tr>";
                 }
    }
}
echo "</table>";
exit;
What is wrong here??
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

The_L wrote:What is wrong here??
You need to escape the "s in the first line, otherwise PHP thinks the string has ended after align=

Code: Select all

echo "<table align=\"center\">";
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

aha..done but again something is wrong..there are two lists one below another...it double-listed the links :D
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: Php link exporter

Post by iankent »

The_L wrote:aha..done but again something is wrong..there are two lists one below another...it double-listed the links :D
Change your parse_array function so it returns $matching_data[0] instead, i.e.

Code: Select all

 
    return $matching_data[0];
 
Then update your main code file to remove the inner foreach loop and rename the outer foreach variable to $link, e.g.

Code: Select all

foreach ($linkarray as $links) {
    if(strpos($link, $search) > -1) {
        echo "<tr>
            <td>$link</td>
            </tr>";
    }
}
my fault sorry, preg_match_all returns an array containing two lists, and we only need the first one
Post Reply