From 4d018fa255659a7c922b37500448a4a258bccbdc Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 30 Jun 2010 11:33:54 -0300 Subject: Stronger bracket handling at IsisConnector --- classes/IsisConnector.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/classes/IsisConnector.php b/classes/IsisConnector.php index f0e5335..db5ac9d 100644 --- a/classes/IsisConnector.php +++ b/classes/IsisConnector.php @@ -281,7 +281,54 @@ class IsisConnector { * Array of matched strings. */ public function explodeBrackets($subject) { - $values = preg_split('/[<\s>]+/', $subject, -1, PREG_SPLIT_NO_EMPTY); + preg_match_all('/<[^<>]*>/', $subject, $values); + + // Why this doesn't work? + //$values = preg_replace(array('//'), '', $values); + + foreach ($values[0] as $key => $value) { + $values[$key] = preg_replace(array('//'), '', $value); + } + return $values; } + + /** + * Check if a string has brackets. + * + * @param $value + * String to be compared. + * @return + * True if string has brackets, false otherwise. + */ + public function hasBrackets($value) { + if (strstr($value, '<') && strstr($value, '>')) { + return TRUE; + } + + return FALSE; + } + + /** + * Explode values from fields or subfields. Split values + * inside brackets if needed, but then doesn't return any + * value outside brackets. + * + * @param $value + * String with values. + * @return + * Array with values. + */ + public function explodeValue($value) { + if ($this->hasBrackets($value)) { + return $this->explodeBrackets($value); + } + else { + if (!is_array($value)) { + $value = array($value); + } + } + + return $value; + } } -- cgit v1.2.3