$string = "last_name, first_name"; $search = array('first_name', 'last_name'); $replace = array('John', 'Smith'); $result = str_replace($search, $replace, $string);