Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
REGEXP:获取PHP变量的内容,即赋值本身。特别是,使用SQL查询搜索变量_Php_Regex_Variables_Variable Assignment - Fatal编程技术网

REGEXP:获取PHP变量的内容,即赋值本身。特别是,使用SQL查询搜索变量

REGEXP:获取PHP变量的内容,即赋值本身。特别是,使用SQL查询搜索变量,php,regex,variables,variable-assignment,Php,Regex,Variables,Variable Assignment,我想我快疯了 我试过很多组合,但我不能用好的 在使用文件\u get\u contents()阅读PHP代码后,我需要在其中查找所有SQL查询 当然,所有这些查询都是变量赋值,如: $sql1 = " SELECT * FROM users u WHERE u.name LIKE '%".$name."%' AND ... ; "; 或 或 因此,您可以看到PHP变量需要考虑很多因素 首先,我尝试了一种近似方法,它是基于获取变量本身和获取其内容相结合的方法 我也尝试在正则表达式模式

我想我快疯了

我试过很多组合,但我不能用好的

在使用
文件\u get\u contents()
阅读PHP代码后,我需要在其中查找所有SQL查询

当然,所有这些查询都是变量赋值,如:

$sql1 = "
  SELECT *
  FROM users u
  WHERE u.name LIKE '%".$name."%' AND ... ;
";

因此,您可以看到PHP变量需要考虑很多因素

首先,我尝试了一种近似方法,它是基于获取变量本身和获取其内容相结合的方法

我也尝试在正则表达式模式中从SQL中查找特定单词

不管怎样

我不知道怎么做

  • 获取所有变量及其赋值,对赋值进行分组,然后在匹配中循环搜索特殊的SQL单词(这就是我现在所做的,但它不起作用,因为赋值正则表达式部分)

  • 使用好的正则表达式直接搜索SQL查询

  • PHP变量(特别是字符串),包含与其他变量的部分连接,双引号和单引号字符串,在“的结尾”或在中间…

    的注释。 那我该怎么办

    到目前为止,这是我的变量regex部分:

    $regex_variable = '\\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*[\+\-\*\/\%\.\&\|\^\<\>]*=\s*';
    

    想象一下,许多程序员在代码中创建查询,任何人都以自己的方式进行查询…:\


    我必须把它们都弄到手。至少,将结果最大化…^^'

    我建议您看看-您可以使用它来标记您的源代码(即解析它以便更容易理解),然后您可以通过标记查找符合您需求的字符串和变量,知道每个标记
    结束一行代码。

    我建议您看看-您可以使用它来标记源代码(即,解析它以便更容易理解),然后您可以通过标记查找符合您需求的字符串和变量,知道每个标记
    结束一行代码。

    不知道这是否是您正在寻找的:

    preg_match_all('/\$.*?=(.*?)(?<=[\'"]);/s', $subject, $result, PREG_PATTERN_ORDER);
    $result = $result[1];
    

    preg\u match\u all('/\$*?=(*?)(不知道这是否是您正在寻找的:

    preg_match_all('/\$.*?=(.*?)(?<=[\'"]);/s', $subject, $result, PREG_PATTERN_ORDER);
    $result = $result[1];
    
    preg\u match\u all('/\$*?=(*?)?
    
    //$regex_sql = '(["\'])(.*?)\2\s*;';
    //$regex_sql = '(["\'])([^;]*?)\2\s*;';
    //$regex_sql = '(?<!")\b\w+\b|(?<=")\b[^"]+';
    //$regex_sql = '([^;]+)(?<=["\']);(?!["\'])';
    //$regex_sql = '(.*?;)[^\\$]*';
    
    $s = 'insert into tabletest(a,b,c) values('asd','r32r32','fdfdf')';
    
    $where = 'where a=2';
    $sql="select distinct * from test ".$where;
    
    $a = '
    select *
    from users
    left outer join ...
    inner join ...
    left join ...
    where ...
    group by ...
    having ...
    order by ...
    limit ...
    ...
    ';
    
    preg_match_all('/\$.*?=(.*?)(?<=[\'"]);/s', $subject, $result, PREG_PATTERN_ORDER);
    $result = $result[1];
    
    "
    \$         # Match the character “\$” literally
    .          # Match any single character
       *?         # Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
    =          # Match the character “=” literally
    (          # Match the regular expression below and capture its match into backreference number 1
       .          # Match any single character
          *?         # Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
    )
    (?<=       # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
       ['\"]       # Match a single character present in the list “'\"”
    )
    ;          # Match the character “;” literally
    "