Parse query string into an array

前端 未结 10 2397
暖寄归人
暖寄归人 2020-11-22 02:58

How can I turn a string below into an array?

pg_id=2&parent_id=2&document&video 

This is the

10条回答
  •  故里飘歌
    2020-11-22 03:29

    This is the PHP code to split query in mysql & mssql

    enter code here
    function splitquery($strquery)
    {
    $arrquery=explode('select',$strquery);
    
    $stry='';$strx='';
    
    for($i=0;$i1)
    {
    
    $strx=trim($arrquery[($i-1)]);
    
        if(trim(substr($strx,-1))!='(')
        {
            $stry=$stry.'
    
    select '.trim($arrquery[$i]);
        }
        else
        {
            $stry=$stry.trim('select '.trim($arrquery[$i]));
        }
    
    $strx='';
    }
    } 
    
    return $stry;
    }
    

    Example:

    Query before

    select xx from xx select xx,(select xx) from xx where y=' cc' select xx from xx left join ( select xx) where (select top 1 xxx from xxx) oder by xxx desc ";

    Query after

    select xx from xx

    select xx,(select xx) from xx where y=' cc'

    select xx from xx left join (select xx) where (select top 1 xxx from xxx) oder by xxx desc

    Thank you, from Indonesia Sentrapedagang.com

提交回复
热议问题