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:[EMAIL PROTECTED]]
Sent: 28 November 2002 13:11
To: [EMAIL PROTECTED]
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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to