aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-06-30 11:33:54 -0300
committerSilvio <silvio@devlet.com.br>2010-06-30 11:33:54 -0300
commit4d018fa255659a7c922b37500448a4a258bccbdc (patch)
tree261c45d3c7116700be63af3b2cdc9f9cfaf9b816
parent4f58de6c799f54e8581e9a911e9aa997dc5b1080 (diff)
downloadcinisis-4d018fa255659a7c922b37500448a4a258bccbdc.tar.gz
cinisis-4d018fa255659a7c922b37500448a4a258bccbdc.tar.bz2
Stronger bracket handling at IsisConnector
-rw-r--r--classes/IsisConnector.php49
1 files changed, 48 insertions, 1 deletions
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;
+ }
}