php - How to store a piece of a name -


i'm trying store piece of first name split firstname can store in table. beginner @ php programming. appriciated, thanks.

$names = 'donny p, raph rsa, leo old, laugh orange';  foreach ($fullnames $fullname) {     $namesplit = explode(" ", $fullname);      if ($names == empty($namesplit[0]) || empty($names)){         echo 'no first name here or no name @ all';         echo '<br>';         echo '<br>';     } elseif ($names == empty($namesplit[1])){         echo 'no last name here';         echo '<br>';         echo '<br>';     } else{         echo 'first name: ' . $namesplit[0];         echo '<br>';         echo 'last name: ' . $namesplit[1];         echo '<br>';         echo 'email address: ' . $namesplit[0] . $email;         echo '<br>';         echo '<br>';     }  } 

below i'm thinking of logically in head, know it's not valid code helps getting idea across.

foreach ($namesplit $namesplits) { store namesplit[0] $firstname; store namesplit[1] $lastname; store namesplit[0] $emailuser; } 

i suggest first explode commas , loop through each 1 of them.

so this:

$exp = explode(",", $names);  foreach($exp $names){     $namesplit = explode(" ", $names);     if($namesplit[0] == ""){ $s = 1; }else{ $s = 0; }      $firstname = $namesplit[$s];     $lastname = $namesplit[$s+1];     //or can loop through other names here starting first position } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -