简体   繁体   English

使用preg_match_all PHP获取字符之间的价值

[英]Get value between character using preg_match_all PHP

This is my code: 这是我的代码:

$str = 'auto_load[>=]';
$result = get_value($str);

function get_value($s) {
   if (preg_match_all('/[(=|>=|<=|~|!~|~!)]/', $str, $m)) {
       //return here...
   }
}

I want it return: ">=" 我希望它返回:“> =”

(accept the return value: "=", ">=", "<=", "~", "!~" or "~!")

Somebody can help me? 有人可以帮助我吗?

[ is a special character used to open a character class. [是用于打开字符类的特殊字符。 if you want to write a literal [ you must escape it (no need to escape ] , it isn't a special character even if it can be used to close a character class, the regex engine is smart enough to know when it is the case) : 如果要编写文字[必须转义(无需转义] ,即使它可以用来关闭字符类,它也不是特殊字符,正则表达式引擎足够聪明,可以知道何时使用情况)

/\[([><]?=|~!?|!~)]/    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM