jd22 Posted September 19, 2011 Share Posted September 19, 2011 i have a value something like enum('adult','kid') (This value is result of "SHOW COLUMNS FROM clases LIKE 'School'" school is where enum values store) how can i parse it those and add into <option value="HERE">HERE</option> Regards Quote Link to comment https://forums.phpfreaks.com/topic/247413-very-easy-regex-not-for-me/ Share on other sites More sharing options...
salathe Posted September 20, 2011 Share Posted September 20, 2011 There's no real need for regex. $enum_string = "enum('adult','kid')"; $values = explode(',', str_replace("''", "'", substr($enum_string, 5, -1))); Then you can just loop over $values to build/output your HTML. Quote Link to comment https://forums.phpfreaks.com/topic/247413-very-easy-regex-not-for-me/#findComment-1270906 Share on other sites More sharing options...
jd22 Posted September 20, 2011 Author Share Posted September 20, 2011 Dear salathe Thank you for your reply. I build a function yesterday it is simple but works fine form. function EnumFileds($Table, $Column) { $DSP_RESULT = ""; $ENUM_NAME = "SHOW COLUMNS FROM " .$Table. " LIKE '" .$Column. "'"; $ENUM_QUERY = mysql_query($ENUM_NAME); $ENUM_ROW = mysql_fetch_array($ENUM_QUERY); $GetCol = preg_match("/['](.*)[']/", $ENUM_ROW['Type'], $matches); $SplitIt = str_replace("'", "", $matches[0]); $Result = explode(",", $SplitIt); for($i=0; $i<count($Result); $i++) $DSP_RESULT .= '<option value="' .$Result[$i]. '">' .$Result[$i]. '</option>'; return $DSP_RESULT; } I hope this code help someone else. Thank you again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/247413-very-easy-regex-not-for-me/#findComment-1270938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.