有没有PHP函数可以在应用regex模式之前对其进行转义?
我正在寻找类似于C# Regex.Escape()
函数的东西。
发布于 2019-05-20 16:43:35
在T-Regx library中使用Prepared Patterns要安全得多
$url = 'http://stackoverflow.com/questions?sort=newest';
$pattern = Pattern::prepare(['\s', [$url], '\s']);
// ↑ $url is quoted
然后执行正常匹配:
$haystack = "Bla bla http://stackoverflow.com/questions?sort=newest bla bla";
$matches = $pattern->match($haystack)->all();
https://stackoverflow.com/questions/1531456
复制相似问题