Removing Links

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

Post Reply
ajay600
Forum Newbie
Posts: 14
Joined: Tue Jan 19, 2010 8:54 am

Removing Links

Post by ajay600 »

I have two web pages and i need the identify the links that are repeated in both the web pages and then , the web page should not display the repeated links ( using the contents of <a> tag)...
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Removing Links

Post by JakeJ »

I assume you mean the 2nd web page should not display the repeated link, not both pages as is implied.

I suppose how you accomplish this partly depends on where you get the links to begin with? Are they coming from a database? User input?

In any case, you should be able to throw them all in array and use the array_unique() function to return an array without duplicates. If the URL's are coming from the database, do it in the query with the DISTINCT or GROUP BY, whichever suits your needs.

I hope that helps.
ajay600
Forum Newbie
Posts: 14
Joined: Tue Jan 19, 2010 8:54 am

Re: Removing Links

Post by ajay600 »

i give 2 web pages as input . i need to store the the link that is specified in the <a> tags of 2 pages in 2 arrays and then compare the arrays and remove all the repated links .

Just like the following code stores all the img src tag content in an array,

i need to store all the link specified in <a href = " www.a.com/pagea"> in an array .

Code: Select all

$doc = new DOMDocument(); 
$doc->loadHTMLFile('www.page_a/source.html');
 
$xpath = new DOMXPath($doc); 
$imgList = $xpath->query('//img');
 
$srcList = array(); 
foreach ($imgList as $img) { 
    $srcList[] = $img->getAttribute('src'); 
}
help me in storing the links in a array
Post Reply