Corresponding to complement with or without postal code hyphen (PHP)

Aug 31, 2020 PHP postal code

A memorandum for saving the postal code entered on the Web page in the DB * In case of PHP

Corresponding to complement with or without hyphen

// Put a hyphen in the variable as a survey string
$pattern ='-';

// Does the input string (zip code) include hyphens?
$pos = strpos($p_data['inZipCode'], $pattern);

// To insert a hyphen if there is no hyphen
if ($pos === false) {
     $chgZipCode = substr_replace($p_data['inZipCode'], $pattern, 3, 0);
// if you want to remove the hyphen
} else {
     $chgZipCode = str_replace($pattern, ``, $p_data['inZipCode']);
}

It is OK if you search for the value input and the converted value at the time of SQL search

Using the above code as is does not work! That’s not true. If you want to refer to it, please read it properly.