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中查找特定单词
不管怎样
我不知道怎么做
$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
"