Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello all

 

I am still working on the login script from this book, and implementation on my own site works very very well

 

At the moment I am strugling with our last-name convention here in Holland

We have names like "van der Vaart", "de Wit" and "in 't Groen" and more alike.

The current script does not take this into account and puts them in alphabetical order. So all the "van" and "de" names are in one row.

Here in Holland it is therefore customary to split the last name like this: "Vaart, van de", "Wit, de" and "Groen, in 't"

But of course we also have singular-word last names, like "Groenen", "Smulders" etc, etc.

 

Does anybody know how I can do this, before injecting them into the database? As a person will always enter it in the orignal way.

I was thinking to search for a space before the last word in that line or so, but I might be digging in the dark, and I don't know how to write the code for that.

 

This is a line from the script which already checks for a last name:

// Check for a last name:

if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) {

$ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']);

} else {

echo '<p class="error">Fill in your last name, please!</p>';

}

 

and the line from the form is as follows:

<tr><td><b>Last Name:</b></td><td><input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></td></tr>

 

Thanks!

 

Mike

Link to comment
Share on other sites

I don't think the regex that checks the last name needs to change.

It seems to me that a valid last name is a valid last name.

Also, I'm not familiar with the conventions for last names in Holland, but from a keeping-the-data-in-the-DB-pure point of view, I'd think that you'd always want to keep at least one copy of the last name in the DB just the way the user typed it.

 

As such, you might want to create a new column in your table that handles the rearranging of certain names, while still preserving the name the way the user originally typed it.

 

As for how to implement what you're asking about, the best solution I can think of is to keep a static list (array) of the sub-last name elements that you want to rearrange. For example, you might have the following array in your PHP:

 

$last_names_to_rearrange = array("van der ", "de ", "in 't ");

 

Then, when you check the input last name, you can check whether the last name contains any of the parts in the $last_names_to_rearrange array. If it does, then you'll want to use the preg_replace function to write a regex that will rearrange the last for you. I'd then store both the original last name and the rearranged last name in separate columns in the DB.

 

Anyway, that's how I'd do it. Please let me know if I misunderstood what you were asking for.

Also, if you'd like specific code, please let me know.

Thanks.

Link to comment
Share on other sites

Hello HartleySan

 

Thanks for your response.

I did figure out a workaround, which is actually commonly used here in Holland. I just did not realize.

 

What most web builders seem to do is make an extra column for these prepositions and ask the users to put them in there and the last part of the last name to enter as last name.

 

I have to correct about 100 last names, but it makes my life eventually a lot easier.

 

Thank you again.

 

Regards

Mike

Link to comment
Share on other sites

Yes, that is probably the simplest solution, and I never knew about that. Cool.

At first, I thought that that might be a bit inconvenient for the user, but then again, if that's standard practice in Holland, then no problem.

 

I have a random question, if you don't mind: Do most people in Holland refer to their country in English as Holland or the Netherlands?

Thanks.

Link to comment
Share on other sites

Hello HartleySan

 

It's a bit of work, but it will safe me a lot of problems later indeed.

Thanks again

 

Holland or The Netherlands is kind of used randomly, but I notice that in the "spoken" language, Holland is more used than "The Netherlands"

In official writing I would say The Netherlands is mostly used.

Though "The Netherlands" is the official English translation. "Holland" is an old term actually, and nowadays in Dutch only used in the name of 2 provencies: North-Holland (Noord-Holland) and South-Holland (Zuid-Holland)

 

This site may explain a bit more:

http://www.archimon.nl/general/holland.html

or

http://www.worldatlas.com/aatlas/infopage/holland.htm

 

 

Regards

Mike

Link to comment
Share on other sites

 Share

×
×
  • Create New...