Hello Jeff, Tuesday, March 16, 2004, 3:24:57 PM, you wrote:
JO> If I have a list like this: JO> Firstname1 LastName1 JO> Firstname2 Lastname2 JO> etc. JO> I can split the names by \n to put them into JO> an array which will then be output into an <option> JO> list for a form. But how do I reverse the names JO> so that the last name is first? Also, how do I JO> handle people with three names? Thanks. <? function swap (&$name) { $tmp_name = trim($name); $pos = strrpos($tmp_name, " "); $first_name = substr($tmp_name, 0, $pos); $surname = substr($tmp_name, $pos); $name = "$surname, $first_name"; } $raw_names = "richard davey susannah davey jeff oien willy three names jack van-der-meet"; $names = explode("\n", $raw_names); echo "<pre>"; print_r($names); array_walk($names, 'swap'); print_r($names); echo "</pre>"; ?> The echo and print_r lines are to show you what it has done. The $raw_names should be your list of names. -- Best regards, Richard Davey http://www.phpcommunity.org/wiki/296.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php