How do I get the middle part of a FULL NAME ??

In GLOBIFLOW

 

How do I get the middle part of a FULL NAME ??  (multiple words?)

I have so far these

 

FirstName = (strpos( [(Contacts) Full Name], " ")) ? (substr( [(Contacts) Full Name] , 0, strpos( [(Contacts) Full Name] , " "))) : ( [(Contacts) Full Name] )

 

LastName = substr( [(Contacts) Full Name] , strrpos( [(Contacts) Full Name] , " " ))

 

How do I get the middle part? say this person is Johnny Boy Jr. Smith


  •  

    input = "Johnny Boy Jr. Smith";

     

    // Split the input string by spaces

    parts = explode(" ", $input);

     

    // Get the first and last parts

    first_name = parts[0];

    last_name = parts[count(parts) - 1];

     

    // Concatenate the first and last parts

    output = first_name . " " . last_name;

     

     

    @Howie Sun​ 

    Selected as Best
  •  

    input = "Johnny Boy Jr. Smith";

     

    // Split the input string by spaces

    parts = explode(" ", $input);

     

    // Get the first and last parts

    first_name = parts[0];

    last_name = parts[count(parts) - 1];

     

    // Concatenate the first and last parts

    output = first_name . " " . last_name;

     

     

    @Howie Sun​ 

    Selected as Best