php - Iterate through array changing all values in an array that match a from/to associated array -
i have list of operating systems. if enters "ubuntu", correct "linux ubuntu". have various other corrections , i'm wondering if there efficient way go through array making these corrections?
i thinking of having associative array name , key pairs; key being "from" field , name being "to". there better way more efficiently?
sample array:
$os = array('ubuntu', 'vmware', 'centos', 'linux ubuntu');
the above values example of of data. of them correct, not though, , need corrected.
what using array preg_grep ( string $pattern , array $input [, int $flags = 0 ] )
[1] kind less or more sophisticated regular expression? might need simple array of corrected (like linux ubuntu) values that.
edit: code example crystal clearance:
$regex = '/^[a-z ]*' . $user_input . '[a-z ]*$/'; $correct_values = {"linux ubuntu", "linux debian", "windows xp", ...}; //const $corrected_value = preg_grep($regex, $correct_values);
Comments
Post a Comment