[PHP] Re: Capitalizing names etc. part II - found a solution

2002-11-01 Thread -[ Rene Brehmer ]-
Hi Richard Archer,

On Thu, 31 Oct 2002 12:24:15 -, you wrote about RE: Capitalizing
names etc. part II - found a solution something that looked like this:

You should consider the fact that, even as surnames, names like
Mackintosh and Mackenzie (and as someone else suggested here 'Macon')
generally should NOT have a capital letter. Mackintosh is an English
name, not Scottish, and people who spell it with a capital K have gotten
their ancestry mixed up somewhere!

I've been made aware of this by a few others in private mail. When writing
this scripple I was doing something I don't usually do: I was blindingly
stearing at getting it to handle the few names I have to deal with, and
not considering that it may have to handle other names sometime in the
future. Normally when I program things like this, I try to make it take
into account every exception to the rule (not error-exception) I can come
up with. Atleast my Excel macros are made that way ... 

Anyway, perhaps a way around this would be to have a known exceptions
list? You could just stick all your Mc/Mac code inside:
   if (in_array($lastname, $mcExceptions)) {
   ...
   }

I considered that after the responses I got ... but it will be a kludge in
the end ... but a necessary one until I come up with a better solution.

At the end of the day, it's really up to the person how they capitalise
their own name, but I guess mind reading is (currently) a bit beyond
PHP.

My own idea for the perfect solution to this, would be to have it take the
incoming contracted name, compare it to a list, and then find the real
name in the list that corresponds to that name.

My problem is, how'd you do that ??? I've got no access to MySQL, so I
can't use that. The incoming name string is the first part of the file
name that holds the biography for that person (if you take a peek at my
site at metalbunny.net/girlz/bios.php you'll know what I mean, haven't
uploaded the revised capper yet), so it will still need that string to
find the correct include for the body of the page.

I haven't even sniffed at the File I/O functions yet...

Rene
-- 
Rene Brehmer
System developer in the making...

This message was written on 100% recycled spam.

Come see! My brand new site is now online!
http://www.metalbunny.net

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




[PHP] RE: Capitalizing names etc. part II - found a solution

2002-10-31 Thread Richard Archer
Hi Rene,

You should consider the fact that, even as surnames, names like
Mackintosh and Mackenzie (and as someone else suggested here 'Macon')
generally should NOT have a capital letter. Mackintosh is an English
name, not Scottish, and people who spell it with a capital K have gotten
their ancestry mixed up somewhere!

Anyway, perhaps a way around this would be to have a known exceptions
list? You could just stick all your Mc/Mac code inside:
if (in_array($lastname, $mcExceptions)) {
...
}

At the end of the day, it's really up to the person how they capitalise
their own name, but I guess mind reading is (currently) a bit beyond
PHP.

Regards,
Rich


-Original Message-
From: -[ Rene Brehmer ]- [mailto:metalbunny;metalbunny.net] 
Sent: 30 October 2002 7:54 pm
To: [EMAIL PROTECTED]
Subject: Capitalizing names etc. part II - found a solution


Hi y'all

A while back I requested help for properly capitalizing names out of
passed string values, as ucwords() and tokenizing didn't do the trick.

Some kind soul gave me this scripple to work with:

 $text = What?No delimiters,shit happens here.this solves all 
 problems.; preg_match_all(/(\w+[,. ?])+/U, $text, $words); 
 foreach($words[0] as $part) $uwords[] = ucfirst($part); $text = 
 implode(, $uwords); echo $text;

Which didn't work at all (even changing the variables to match my own),
but only got me several errors for each line...

My task was to make it take a string like
firstname_middlename_firstlastname-lastlastname and properly
capitalize it. Also wanted it to do it correctly with names like
O'Connor, MacEnroe, McCarthy and such... The scribble above would be
able to do it with the O'Connors and name-name formats, but useless with
Mac/Mc names ... plus the above script part didn't work at all on my
system (PHP 4.2.3 on Apache 2.0.40 on WinXP Pro).

OK ... so I wanted a compact structure that could do this easily, and
correctly, on ANY name I threw at it...so I've spent a couple of hours
finding useful functions in PHP that would do the trickery easiest ...
and ended up with this:

$name = $HTTP_GET_VARS['name'];

// pull real name out of $name
$realname = ;
// okay, let's get the names cap'ed correctly...
$startat = 0; // these vars are used for substring pulling $stoplen = 0;
// parse 1, find funny chars and cap after them for ($i = 0; $i 
strlen($name); $i++) {
   $ltr = substr($name, $i, 1); // pull out letter i of name
   $stoplen = $i - $startat;  // set the stop point for substring
   // if current letter is a marker
   if ($ltr == _ | $ltr == - | $ltr == ') {  
  // add substring
  $realname .= ucfirst(substr($name, $startat, $stoplen));  
  $startat = $i + 1;  // set new start point for substring
   }
   if ($ltr == _) {  // if space, add space
  $realname .=  ;
   }
   elseif ($ltr == -) { // if dash, add dash
  $realname .= -;
   }
   elseif ($ltr == ') {
  $realname .= ';
   }
}
// the last name won't be added in parse 1,
// this piece adds the last name AFTER checking and capping for Mac/Mc
// so this is essentially pass 2 $lastname = substr($name, $startat,
$stoplen + 1); // find Mac/Mc $maclen = 0; // we set this to zero to
make it easier to check for found if (strstr($lastname, mc) != false)
{  // if Mc is found...
   $maclen = 2;
}
elseif (strstr($lastname, mac) != false) {  // if Mac is found
   $maclen = 3;
}
if ($maclen  0) {  // add the MacSomething with proper capitalization
   $realname .= ucfirst(substr($lastname, 0, $maclen));
   $realname .= ucfirst(substr($lastname, $maclen, strlen($lastname)));
} else { // if we can't find Mac/Mc, just add the last name...
   $realname .= ucfirst($lastname);
}
// end namegame

The curious thing is that this actually runs faster than the strtok() +
ucwords() combo I had before, plus it does the trick correctly,
everytime. If anyone can see a more efficient way of doing this, I'm all
for it.

Do note that I've intentionally made it so that the last word of all
names won't be added to the $realname, until it's determined whether or
not it starts with Mac/Mc. The point to this is simple: It's a lot more
complicated to scan for the Mac/Mc after the full name is assembled,
than it is while it's being built. My structure also ensure that if
someone's called something like Mackenzie for first name, it will not be
incorrectly cap'ed, as it only does the scotch-check on the last
names...

If you can do this simpler, or have any comments for this way of doing
it, please let me know. You may freely copy and dsitribute this as you
wish.

Rene
-- 
Rene Brehmer
System developer in the making...

This message was written on 100% recycled spam.

Come see! My brand new site is now online! http://www.metalbunny.net


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