note 45115 added to function.explode
| From: | fms at hy dot com dot br | Date: | Thu, 26 Aug 2004 14:20:43 +0000 |
| Subject: | note 45115 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75337@lists.php.net to get a copy of this message | ||
This function could be usefull if you need to parse a "SELECT" command into blocks with
(select, from, where, group by, order by) of data.
function parseSELECT(&$q) {
/*****************
by FMS & XANDE on Ago/2004
$q contains a SELECT comand. Example:
SELECT row_id,fullname as name,age FROM tabletest WHERE row_id<10 GROUP BY row_id ORDER BY
age,name
*****************/
// ensures that all keywords are in lowercase
$q=eregi_replace("select" ,"select" ,$q);
$q=eregi_replace("from" ,"from" ,$q);
$q=eregi_replace("where" ,"where" ,$q);
$q=eregi_replace("group by","group by",$q);
$q=eregi_replace("order by","order by",$q);
// does the job
$orderby=explode("order by",$q);
$groupby=explode("group by",$orderby[0]);
$orderby=$orderby[1];
$where =explode("where" ,$groupby[0]);
$groupby=$groupby[1];
$from =explode("from" ,$where[0]);
$where =$where[1];
$select =explode("select" ,$from[0]);
$from =$from[1];
$select =$select[1];
// prepares an array to return
$rt['select' ]=$select;
$rt['from']=$from;
$rt['where']=$where;
$rt['groupby']=$groupby;
$rt['orderby']=$orderby;
return $rt;
}
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45115
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45115&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45115&report=yes
Search -- http://master.php.net/manage/user-notes.php