Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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
Php Atom编辑器中的正则表达式替换_Php_Regex_Atom Editor - Fatal编程技术网

Php Atom编辑器中的正则表达式替换

Php Atom编辑器中的正则表达式替换,php,regex,atom-editor,Php,Regex,Atom Editor,我想更换$\u POST[“type”]到带标签($_POST[“type”])(我想过滤用户的POST操作中的所有html标记) 但是在我的整个项目中,我有200多篇文章,比如 $_POST["role"]; $_POST["uesrname"]; 如何使用Regex添加此函数?此处不需要Regex,-为每个POST变量在循环中调用strip: $postFiltered = []; foreach ($_POST as $k => $v) { $postFiltered[] =

我想更换
$\u POST[“type”]
带标签($_POST[“type”])(我想过滤用户的
POST
操作中的所有html标记)

但是在我的整个项目中,我有200多篇文章,比如

$_POST["role"];
$_POST["uesrname"];

如何使用Regex添加此函数?

此处不需要Regex,-为每个POST变量在循环中调用strip:

$postFiltered = [];
foreach ($_POST as $k => $v) {
  $postFiltered[] = strip_tags($_POST[$k]);
}

您可以尝试搜索以下正则表达式:

(\$_POST\["[^"]+"])
并替换为:

strip_tags($1)
解释 之前 之后
我打赌你已经试过几次了。你有没有可能和我们分享一些失败的东西?我试着搜索
\$\u POST\[“{1,50}”\],我得到了232个结果,但我不能用strip_tags()函数来包围它。我建议不要这样做。我所见过的每一个改变了POST或GET值的项目都对此感到遗憾。您将永远无法恢复原始的发布值。如果你想走这条路,请使用一个单独的筛选post变量。同意@Matt。但是,当您将value替换为键的strip_标记时,该函数无论如何都不起作用。编辑:对不起,我的错。我看错了。但我还是同意马特的观点
(): Capture the value to use it in the replace as `$1`
\$_POST: Locate the `$_POST` and the backslash to escape the `$`
\[]: Escape the opening square bracket
": Start of the quotes
\[^"]+: Take whatever inside that is not a quote
$_POST["type"]
$_POST["role"]
$_POST["username"]
strip_tags($_POST["type"])
strip_tags($_POST["role"])
strip_tags($_POST["username"])