RE: [PHP] Bizarreness with htmlentities() and other things
| From: | Rich Gray | Date: | Thu, 28 Nov 2002 14:07:39 +0000 |
| Subject: | RE: [PHP] Bizarreness with htmlentities() and other things | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-126410@lists.php.net to get a copy of this message | ||
Hi James
There is a bug in PHP for the capitalisation problem
http://bugs.php.net/bug.php?id=14655
If you check the link then a workaround was posted by someone.
HTH
Rich
-----Original Message-----
From: James Coates [mailto:jamesc@affection.net]
Sent: 28 November 2002 13:11
To: php-general@lists.php.net
Subject: [PHP] Bizarreness with htmlentities() and other things
Hello!
I'm currently doing some work that requires a mySQL database of actor
names. For all my actors, I have three columns; first_name, last_name and
between_name. Because between_name can be written in many ways ("Peter van
Wibble" or "Fred d'Angelo), and the French have a habit of writing their
surnames in capitals, I wrote a little function to prepare the actor names
for output:
<?
function actor_name($last,$middle,$first) {
// because we have so many different name combinations, write out a string
// that does capitalisation and the like properly (hopefully)
// ex: actor_name("ANGELO","d'","Jean-Pierre") = Jean-Pierre
d'Angelo
// strtolower() everything because ucwords() doesn't work on mixed case
$last=strtolower($last);
$middle=strtolower($middle);
$first=strtolower($first);
// split hyphenated names so we can ucwords() them
if (strpos($last,"-")) {
$lasthyphen=true;
$last=ereg_replace("-"," ",$last);
} else { $lasthyphen=false; }
if (strpos($first,"-")) {
$firsthyphen=true;
$first=ereg_replace("-"," ",$first);
} else { $firsthyphen=false; }
// if the "middle" name doesn't end with an apostrophe, add a space and
// lowercase it just in case someone's mis-typed it
if (!strrpos($middle,"'")) {
$middle.=" ";
}
$last=ucwords($last);
$first=ucwords($first);
if ($lasthyphen==true) { $last=ereg_replace(" ","-",$last); }
if ($firsthyphen==true) { $first=ereg_replace(" ","-",$first); }
return htmlentities("$first $middle$last");
}
?>
Thing is, I'm getting bizarre behaviour where some characters become
modified in a way I don't like - in particular, when the letter L follows
an E with a diaresis (Raphaël, for example) it becomes upper case.
Suggestions, anyone?
And if anyone wants to make that code shorter and more readable, I'd
appreciate it greatly. :-)
James.
xx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php