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 »

still error...
Warning: Invalid argument supplied for foreach() in /nfs/c02/h10/mnt/30579/domains/forum-racunara.com/html/taggrab.php on line 100
This is your code:

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>";
And this is the one that works...

Code: Select all

echo "<h2>Links present on page: ".$urlrun."</h2><br />";
// Loop to pump out the results
echo "<table align=\"center\" bordercolor=\"#006600\" bgcolor=\"#CCCCCC\">";
$search = 'http://rapidshare.com/'; // matches *.rapidshare.com/
foreach ($linkarray as $link) {
    if(strpos($link, $search) > -1) {
$link = rtrim($link, "\"");
        echo "
        <tr>
           <td>$link</td>
  </tr>";
    }
}
echo "</table>";
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 »

So if that one works whats the problem?

The reason the first code block doesn't work is because its reverted to having the extra foreach loop that we dropped many posts ago. Anyway, if it works, problem solved?
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

The difference is in the array function...
The one that woks exports just .rapidshare.com links i wanna add few more..:/
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:The difference is in the array function...
The one that woks exports just .rapidshare.com links i wanna add few more..:/
Then have a think about how you're currently identifying rapidshare links and how you can extend that to include additional patterns. Throughout the last 7 pages you've definately got all the code you need to do it :)

Take a backup of what you have now while its working, try some changes (just one or two at a time, and undo them if they break it completely) to try and get it doing what you want, and if you get stuck let me know :)
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

I just want to add

Code: Select all

array('.rapidshare.com','http://rapidshare.com');
but you got me confused with
To use an array you just need to add another loop inside your existing ones
Shouldnt i just change $search = ... to $search = array("....???
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:I just want to add

Code: Select all

array('.rapidshare.com','http://rapidshare.com');
but you got me confused with
To use an array you just need to add another loop inside your existing ones
Shouldnt i just change $search = ... to $search = array("....???
Yep, just add extra patterns to the end of the $search array - you dont need to add another loop as that bits already been done.

edit: to add a 'dont' lol... kinda changes the whole answer
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

edit: to add a 'dont' lol... kinda changes the whole answer
Sorry i'm kinda bad at English..:/
Didn't quite catch that...
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:
edit: to add a 'dont' lol... kinda changes the whole answer
Sorry i'm kinda bad at English..:/
Didn't quite catch that...
sorry, didn't explain it well! I'd originally posted this:
Yep, just add extra patterns to the end of the $search array - you need to add another loop as that bits already been done.
which says "you need to add", but I meant this:
Yep, just add extra patterns to the end of the $search array - you dont need to add another loop as that bits already been done.
which as you can see, means the complete opposite!
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

$search = array('.rapidshare.com','.storage.to');
This is the line....but now script 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:

Code: Select all

$search = array('.rapidshare.com','.storage.to');
This is the line....but now script does not list anything..:/
and thats all you changed from the version that was working?
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Yep...
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:Yep...
could you post the full code again, if thats all you've changed then it should still be outputting at least rapidshare links
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 "<h2>Links present on page: ".$urlrun."</h2><br />";
echo "<table align=\"center\" bordercolor=\"#006600\" bgcolor=\"#CCCCCC\">";
$search = array('.rapidshare.com','.storage.to');
foreach ($linkarray as $link) {
    if(strpos($link, $search) > -1) {
$link = rtrim($link, "\"");
        echo "
        <tr>
           <td>$link</td>
  </tr>";
    }
}
echo "</table>";
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:

Code: Select all

echo "<h2>Links present on page: ".$urlrun."</h2><br />";
echo "<table align=\"center\" bordercolor=\"#006600\" bgcolor=\"#CCCCCC\">";
$search = array('.rapidshare.com','.storage.to');
foreach ($linkarray as $link) {
    foreach($search as $search_term) { // this line had gone
        if(strpos($link, $search_term) > -1) { // this line should contain $search_term not $search
            $link = rtrim($link, "\"");
            echo "
                <tr>
                <td>$link</td>
                </tr>";
        }
    } // this line had gone
}
echo "</table>";
looks like you've removed the foreach bit for $search. $search is an array, so you have to loop through that and run strpos against each array element
The_L
Forum Commoner
Posts: 64
Joined: Sun Nov 22, 2009 6:53 pm

Re: Php link exporter

Post by The_L »

Nope,does not list anything...:/
First i added and replaced all you commented...and nope nothing listed...
And then i just copyed your code from here and again...nothing...
Post Reply