]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - misc/strings.php
Fix setting zlines on idents, reported by Jellis
[irc/unrealircd/unrealircd-webpanel.git] / misc / strings.php
index 1d0c158f2d72c4677f84c65025fb3caf9627bae4..f5d576753ee66e197be5aac0deb49d41afa7f679 100644 (file)
@@ -1,5 +1,10 @@
 <?php
 
+function to_slug($str)
+{
+       return str_replace(['-', ' '], '_', strtolower($str));
+}
+
 /** Splits up a string by a space
  * (chr 32)
  *
@@ -165,4 +170,41 @@ function BadPtr(&$tok)
        if (!isset($tok) || empty($tok) || !$tok || strlen($tok) == 0)
                return true;
        return false;
-}
\ No newline at end of file
+}
+
+/** This function takes a string, tokenizes
+ * it by a space (chr 32), removes the first
+ * word/token, and returns the result.
+ * Mostly used for string manipulation around
+ * the source.
+ * 
+ * Syntax:
+ * rparv(String $sentence)
+ * 
+ * Returns:
+ * string|false
+ */
+function rparv($string)
+{
+       $parv = split($string);
+       $first = strlen($parv[0]) + 1;
+       $string = substr($string, $first);
+       if ($string)
+               return $string;
+       return false;
+}
+
+/* Taken from https://www.aviran.org/stripremove-irc-client-control-characters/
+ * We may want to re-base it off our UnrealIRCd's one though.
+ */
+function StripControlCharacters($text)
+{
+    $controlCodes = array(
+        '/(\x03(?:\d{1,2}(?:,\d{1,2})?)?)/',    // Color code
+        '/\x02/',                               // Bold
+        '/\x0F/',                               // Escaped
+        '/\x16/',                               // Italic
+        '/\x1F/'                                // Underline
+    );
+    return preg_replace($controlCodes,'',$text);
+}