gpt4 book ai didi

php - addslashes() for preg_replace() 和 co.?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:52:56 24 4
gpt4 key购买 nike

如何转义传入数据,以便在 preg_replace() 和 consorts 中将其用作模式?例如,我需要匹配这个字符串:

/vorschau/

显然,我需要对“v”进行转义,否则会出错。

我在文档中找不到任何内容。是否有某种 addslashes() 或表达式中的解决方法?

最佳答案

如果我没有正确理解你的问题,你正在寻找 preg_quote :

string preg_quote  ( string $str  [, string $delimiter = NULL  ] )

preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax.
This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters.

The special regular expression characters are: . \ + * ? [ ^ ] $ ( )
{ } = ! < > | : -

关于php - addslashes() for preg_replace() 和 co.?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1921087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com