taratula
taratula

Reputation: 497

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?

Upvotes: 0

Views: 57

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89574

[ 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):

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

Upvotes: 1

Related Questions