JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added: enc_cap(), enc_htmlbrtab()
authorJason Woofenden <jason283@herkamire.com>
Tue, 9 Dec 2008 19:05:40 +0000 (14:05 -0500)
committerJason Woofenden <jason283@herkamire.com>
Tue, 9 Dec 2008 19:05:40 +0000 (14:05 -0500)
encode.php

index db0cde3..11d60db 100644 (file)
 # will encode foo (using enc_html()) before displaying it, so that characters
 # such as < will display properly.
 
+function enc_cap($str) {
+       $str = ucfirst($str);
+       return $str;
+}
 
 function enc_jsdq($str) {
        $str = enc_sql($str);
@@ -49,13 +53,24 @@ function enc_html($str) {
 
 # Encode for output in html. Convert newlines to <br />
 #
-# Example: <p>~foo.html~</p>
+# Example: <p>~foo.htmlbr~</p>
 function enc_htmlbr($str) {
        $str = enc_html($str);
        $str = str_replace("\n", "<br />\n", $str);
        return $str;
 }
 
+# Encode for output in html. Preserves newlines and indentation by converting
+# newlines to <br /> and spaces at the begining of lines to &nbsp;&nbsp;
+#
+# Example: <p>~foo.htmlbrtab~</p>
+function enc_htmlbrtab($str) {
+       $str = enc_htmlbr($str);
+       $space_to_nbsp = create_function('$matches', 'return str_repeat(\'&nbsp;\', strlen($matches[0]) * 2);');
+       $str = preg_replace_callback("|^ *|m", $space_to_nbsp, $str);
+       return $str;
+}
+
 # Encode for output in html. Spaces converted to &nbsp;
 #
 # Example: <option value="12">~foo.htmlnbsp~</option>