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 cleanProperNoun s($name)
{
$words = explode(' ',strtolower($n ame));
echo '<br>Before';
print_r($words) ;
foreach($words as &$w)
$w = trim($w);
echo '<br>After';
print_r($words) ;
return htmlspecialchar s(ucwords(implo de(' ',$words)));
}
echo cleanProperNoun s('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?
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 cleanProperNoun s($name)
{
$words = explode(' ',strtolower($n ame));
echo '<br>Before';
print_r($words) ;
foreach($words as &$w)
$w = trim($w);
echo '<br>After';
print_r($words) ;
return htmlspecialchar s(ucwords(implo de(' ',$words)));
}
echo cleanProperNoun s('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?
Comment