summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/Utils/CharArmor.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Utils/CharArmor.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/src/Utils/CharArmor.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Utils/CharArmor.php b/www/wiki/extensions/SemanticMediaWiki/src/Utils/CharArmor.php
new file mode 100644
index 00000000..9a1e20c0
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/src/Utils/CharArmor.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace SMW\Utils;
+
+/**
+ * @license GNU GPL v2+
+ * @since 3.0
+ *
+ * @author mwjames
+ */
+class CharArmor {
+
+ /**
+ * Remove invisible control characters and unused code points (using a
+ * negated character class to avoid removing spaces)
+ *
+ * @see http://www.regular-expressions.info/unicode.html#category
+ * @since 3.0
+ *
+ * @param string $text
+ *
+ * @return text
+ */
+ public static function removeControlChars( $text ) {
+ return preg_replace('/[^\PC\s]/u', '', $text );
+ }
+
+ /**
+ * @since 3.0
+ *
+ * @param string $text
+ *
+ * @return text
+ */
+ public static function removeSpecialChars( $text ) {
+ return str_replace(
+ [ '&shy;', '&lrm;', " ", " ", " " ],
+ [ '', '', ' ', ' ', ' ' ],
+ $text
+ );
+ }
+
+}