Page 1 of 1
Removing Links
Posted: Wed Jan 27, 2010 7:03 am
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)...
Re: Removing Links
Posted: Wed Jan 27, 2010 1:24 pm
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.
Re: Removing Links
Posted: Wed Jan 27, 2010 10:21 pm
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