I am trying to write a simple function that will take a string containing an
address line or business name and return it nicely formatted.
By this I mean extra spaces removed and words capitalised.
I also wish it to be legal XML..
The result string is further sent to another function to check
the names and addresses don't appear on a blacklist
which is why the extra spaces need removing.
This is my test function so far
[PHP]function cleanProperNouns($name)
{
$words = explode(' ',strtolower($name));
echo '<br>Before';
print_r($words);
foreach($words as &$w)
$w = trim($w);
echo '<br>After';
print_r($words);
return htmlspecialchars(ucwords(implode(' ',$words)));
}
echo cleanProperNouns('this & is a test name '); [/PHP] It does not remove all the extra spaces in the string.
It looks fine in a browser but source is not.
Has anybody written a function that does something similar or got any better ideas?