Forum Moderators: open

Message Too Old, No Replies

How to Alphabetize hand-coded HTML links list?

alphabetize list written in html code

         

wiggy

4:11 pm on Oct 15, 2006 (gmt 0)

10+ Year Member



I have some lists of links on my website that I would like to alphabetize by Site Name to make any particular site easier for users to find.

My lists are in hand-coded HTML, and if I try to copy and paste them into Excel to alphabetize them, the HREF linking information gets deleted.

How can I alphabetize my lists of links (other than manually copying and pasting them one by one in proper order myself)?

Thanks!
wiggy

Little_G

5:02 pm on Oct 15, 2006 (gmt 0)

10+ Year Member



Hi,

Here's some PHP that will do it:


<?php
echo "<pre>";
$pattern = "/<a[\s]+[^>]*?href[\s]?\=[\s\"\']*([\w:?=@&\/#._;-]+)[\s\"\']*.*?\>([^<]+¦.*?)?<\/a>/";
preg_match_all($pattern, file_get_contents("http://www.google.com/"), $matches);
array_multisort($matches[2],$matches[1]);
for($i=0;$i<count($matches[0]);$i++){
echo $matches[2][$i], ',', $matches[1][$i], "\n";
}
echo "</pre>";
?>

Andrew