It's going to be harder for us than for you to figure out ...
The first thing most people will tell you, is to use the XML library. That's not bad advice depending on what the "links.htm" file tends to look like.
But it's possible with regex ... also, depending on what the file looks like.
As a matter of fact, many times the problem with a parsing routine is actually a problem with the data you're feeding it ... GIGO, and all that. A script is typically created to do a certain thing in a certain way ... if you have a tool that does really well with a lot of different types of inputs, chances are you've paid a lot for it, one way or the other ...
I can give you this by way of example of a regex approach:
my_file.txt :
<a href='example.com/bar' class='foo'>Dead</a>
<a href='example.com/barz' class='fao'>Arachnid</a>
<a href='example.com/dfdfbar' class='fool'>Colt</a>
<a href='example.com/bbar' class='food'>Kid</a>
<a href='example.com/bbbbar' class='foaaa'>Zeke</a>
<a href='ombe.com/barrrrrrr' style="left:123;top:none">You</a>
sort.php:
<?php
$out = array();
$d = file("./my_file.txt");
//I'm sure there are much better expressions.
$regex = "%(.*)>(.*)<(.*)%";
foreach ($d as $data) {
// echo "checking $data".PHP_EOL;
preg_match($regex, $data, $matches);
$href = $matches[1];
$text = $matches[2];
$out["$text"]=$href.">".$text."</a>";
}
//$out is now an array like "Link Text"=>"Link HTML", etc.
ksort($out); // sort by key
print_r($out);