My PHP function that reads names and attempts to fix the suffixes
If it can be assumed that a suffix will always have a space before it this is easier. 

Loop through suffixes and see if one is in the first name.  Strip out the suffix if is is there.  Any suffix that is found is added to a suffix variable, s.  

Treating the suffix separately is nice because it can be added, separated, lower cased, modified etc.  For example, suffixes could be standardized; "SR." and "SR" could all be "SR." in the final name. This is easier to do if suffix is a separate variable.  It could be an array as well. 

function extractFullName($name) {

    // $suffixes = ['II', 'III', 'IV', 'JR.', 'SR.'];
    // Suffixes would always have a space before them
    $suffixes = [' II', ' III', ' IV', ' JR.', ' SR.'];


    // lets first assemble a full name from the row
    $fullNameArray = explode(",", $name);
    $firstName = trim($fullNameArray[1]);
    $lastName = trim($fullNameArray[0]);
    $s = ''; // default zero length string.
    // 
    //lets look at the FIRST NAME for II/III/IV/JR./SR.
    foreach ($suffixes as $suffix) {
        if (strpos($firstName, $suffix)) {
            // Suffix was found, remove it from first name
            $firstName = str_replace($suffix, "", $firstName);
            $s .= $suffix;  // keep ths suffixes stored separately.
        }
    }

    //Basically arranging it in a 'firstname lastname II/III/IV/JR./SR.' format
    $fullName = $firstName . " " . $lastName;
    $finalName = ucwords(strtolower($fullName)) . " " . $s;
    return $finalName;
}

$name1 = 'MILLERS, WALTER M IV';
$name2 = 'MIVERS, LIVEY M IV';  // test for IV in the middle of a name
$name3 = 'DUPONTE, THOMAS B. II';
$name4 = 'DUPONTE, THOMAS B. II SR.';  // test for multiple suffixes.
$name5 = 'HARDIWAY, GRANT U. SR.';
$name6 = 'GUIDRY, PAUL JOHN';
echo extractFullName($name1) . "&lt;br&gt;";
echo extractFullName($name2) . "&lt;br&gt;";
echo extractFullName($name3) . "&lt;br&gt;";
echo extractFullName($name4) . "&lt;br&gt;";
echo extractFullName($name5) . "&lt;br&gt;";
echo extractFullName($name6) . "&lt;br&gt;";