问题描述
任何想法?
MySQL regexps是扩展的POSIX变体(ERE),可以在PHP中作为不推荐使用的 ereg _
函数。 p>
不幸的是,PHP中没有 ereg_quote
,但是PCRE的特殊字符是ERE的特殊字符的超集,反斜杠转义非特殊的标点符号不会对其造成伤害,因此您可以安全地使用 preg_quote
来避免。
(当然,您将需要参数化查询或 mysql_real_escape_string
在引用之后,为了阻止反斜杠被误解为MySQL的非 - ANSI标准字符串文字转义。)
I'm looking for something similar to preg_quote, but for the MySQL regexp syntax.
Any ideas?
MySQL regexps are the ‘extended’ POSIX variant (ERE), available in PHP as the deprecated ereg_
functions.
Unfortunately there is no ereg_quote
in PHP, however PCRE's special characters are a superset of ERE's special characters, and backslash-escaping a non-special punctuation character doesn't harm it, so you can get away with using preg_quote
safely.
(Naturally you will need parameterised queries or mysql_real_escape_string
after that quoting, to stop the backslashes being misinterpreted as MySQL's non-ANSI-standard string literal escapes.)
这篇关于PHP函数来转义MySQL regexp语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!