function MessagesAlter::matchByType in Custom Submit Messages 7.x
Same name and namespace in other branches
- 7 messages_alter/lib/MessagesAlter.7.x-1.3.php \MessagesAlter::matchByType()
Does a regex by message type (status, warning, error)
Pretty much just a wrapper of preg_match
1 call to MessagesAlter::matchByType()
- MessagesAlter::match in messages_alter/
lib/ MessagesAlter.6.x-1.3.php - Matches a regex that you provide.
File
- messages_alter/
lib/ MessagesAlter.6.x-1.3.php, line 86 - Contains the MessagesAlter class
Class
- MessagesAlter
- Defines the MessagesAlter class.
Code
function matchByType($type, $regex) {
$matches = array();
$has_match = FALSE;
if (isset($this->messages[$type]) && is_array($this->messages[$type])) {
foreach ($this->messages[$type] as $k => $v) {
if ($cnt = preg_match($regex, $v, $m)) {
/*
* I'm returning everything because
* I'm not exactly sure how you're going
* to use this in your code
*/
$matches[] = array(
'type' => $type,
'search' => $regex,
'index' => $k,
'message' => $v,
'count' => $cnt,
'matches' => $m,
);
$has_match = TRUE;
}
}
}
return $has_match ? $matches : FALSE;
}