How to remove white space underline at end of links...

This is a very short and quick solution for web designers. The situation of today is an style link becomes trashed when having any kind of white spaces just before the closing

Imagine a link like:

<a title="example">
 example
</a>

will result in a display like:
example 

This is a bug of all browsers I know, but there is a quick PHP fix for it:

$html_source = preg_replace( "/\s+<\/a>/i", "</a>", $html_source );

Voilà! All white spaces infront of the closing tag are removed and you can echo() the html source code.

EDIT: Recently it appeared there are other cases where line-breaks and other white-spaces may confuse web-browsers. I therefor extended the above example a bit to handle all white-spaces infront of closing tags. Here it is:

$site_source = preg_replace( "/\s+<\/([a-z]+)>/i", "</$1>", $site_source );

How it works:
It's a regular expression that searches for \s (=white spaces) right in front of the closing tag (,

,

,

whatever!). Each occurrence will be replaced.

The trick is to remember the name of the closing tag and replace all the white-space characters and the closing tag itself by the closing tag only. The $1 back references the closing tags content which is marked by braces ().

Requirements:
Of course you need a PHP driven website and must be using some kind of output buffering. Probably the RegEx will work in any other language. Even a JavaScript would work fine to remove all those white spaces just before the page is rendered at the user's graphical browser. It you'd like to build a JavaScript for removing the white spaces from html links, please tell me so I could post the JavaScript here!

Take the performance into account
Using regular expression requires some performance. It might slow down your website a bit. In my case it's no problem, but I don't know your server or provider! Just a warning...