diff options
Diffstat (limited to 'it.class')
-rw-r--r-- | it.class | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -240,11 +240,11 @@ function toascii($text) /** * Convert regex for preg (adds and escapes delimiter, adds modifiers) * @param $pattern Regex to convert - * @param named parameter casesensitive Regex is case sensitive (omit modifier i) - * @param named parameter multiline add modifier m - * @param named parameter singleline add modifier s - * @param named parameter utf8 add modifier u - * @param named parameter extended add modifier x + * @param $p['casesensitive'] Regex is case sensitive (omit modifier i) + * @param $p['multiline'] add modifier m: ^ and $ match \n + * @param $p['singleline'] add modifier s: . matches \n + * @param $p['utf8'] add modifier u + * @param $p['extended'] add modifier x * @return converted regex to use with preg */ function convertregex($pattern, $p = array()) @@ -270,22 +270,25 @@ function convertregex($pattern, $p = array()) } /** - * Try to match string against regex. See convertregex for additional named parameters. + * Try to match string against regex. Case insensitive by default. * @param $pattern Regex to match against * @param $string String to match - * @param named parameter offset_capture Set flag preg_offset_capture (returns offsets with the matches). - * @param named parameter all Return every match as array instead of first match. + * @param $p['offset_capture'] Set flag preg_offset_capture (returns offsets with the matches). + * @param $p['all'] Return every match as array instead of first match. + * @param $p['locale'] Use given locale (default: de_CH), mainly affects handling of iso-latin chars + * @param $p contains pattern modifiers, @see convertregex() * @return Matched string or false */ function match($pattern, $string, $p = array()) { $flags = 0; + $p += array('locale' => 'de_CH'); if($p['offset_capture']) $flags |= PREG_OFFSET_CAPTURE; $oldlocale = setlocale( LC_CTYPE, 0 ); - setlocale(LC_CTYPE, 'de_CH'); + setlocale(LC_CTYPE, $p['locale']); if ($p['all']) $r = preg_match_all(it::convertregex($pattern, $p), $string, $m, $flags | PREG_PATTERN_ORDER, $p['offset']); |