note 33596 added to function.mysql-field-type

From: Date: Tue, 01 Jul 2003 16:29:09 +0000
Subject: note 33596 added to function.mysql-field-type
Groups: php.notes 
Request: Send a blank email to php-notes+get-51292@lists.php.net to get a copy of this message
There's a small "bug" in the following line (submitted by "e at eikimartinson dot c0m"): $values = split(",", preg_replace("/'/", "", $matches[1])); It doesn't allow the user to specify an , inside one of the values. Instead use something like: $values = preg_split("/','/", substr($matches[1], 1, -1)); The entire script will then be: $result = mysql_query("SHOW FIELDS FROM database_name.table_name LIKE 'enum_column_name'"); $row = mysql_fetch_array($result); if (preg_match("/^enum\((.*)\)$/", $row['Type'], $matches)) { $values = preg_split("/','/", substr($matches[1], 1, -1)); } An alternative way, is to "remove" the first and last ', directly in the "if (preg_match ..." :-) ---- Manual Page -- http://www.php.net/manual/en/function.mysql-field-type.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33596 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33596&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33596&report=yes

« previous php.notes (#51292) next »