I have seen some news sites that for the print preview
page automatically generate a list of references at the
end of the article. This list is showing all the links
from the page with the corresponding URLs. Here is an
You can see a sample of this code at work here:
Just hit the print button.
A few observations:
- if the URL and the display text are identical
(identity links) then they don't show up in the list
- if the URL and the display text are almost identical
(lookalike links) then again they don't show up,
'almost' means: 'http://' prefix and '/' suffix
- internal links (using the # fragment) are not listed
- for tags the single or double quotes around the
href attribute value are required
This was implemented by adding one method to the
MyTextSanitizer class, it is called extractLinks. In
order to add the list of links to your preview page you
have to call this method and then display the list.
Here is an example for the News module:
$fulltext = $story->hometext . $story->bodytext;
$links = $myts->extractLinks ($fulltext);
if (!empty ($links))
" . htmlspecialchars ($link) .