Bizarreness with htmlentities() and other things

From: Date: Thu, 28 Nov 2002 13:10:47 +0000
Subject: Bizarreness with htmlentities() and other things
Groups: php.general 
Request: Send a blank email to php-general+get-126404@lists.php.net to get a copy of this message
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

« previous php.general (#126404) next »