php - String comparison with alternate character variables -



php - String comparison with alternate character variables -

right problem...user need input text (to specific input text serial number), input must compared database. because of little print user create error between characters like: (b/8), (1/l),(0,o),(u,v).

the question how create user input "l234b" valid entry when serial number "12348"??

here examples: o12u3 ---> 012v3

thanks.

some solution might replace occorences "8" "[8b]" match against both possibilities:

$sn = "l234b"; $sn_new = ""; $problematic_chars = ['b' => 'b8', '8' => 'b8', '1' => '1l', 'l' => '1l', ...]; // go through original string , create new string // "l234b" becomes "[1l]234[8b]" for($i = 0; $i < strlen($sn); $i++) { $char = $sn[$i]; if (array_key_exists($char, $problematic_chars)) { $sn_new .= "[".$problematic_chars[$char]."]"; } else { $sn_new .= $char; } } // query stuff $sql = "select * table_name sn regexp '^${sn_new}\$'";

did not write php long time, think idea.

php regex string comparison preg-match

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -