JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
file_run() expects _main suffix. added: enc_htmlbr enc_provinces
authorJason Woofenden <jason183@herkamire.com>
Fri, 14 Sep 2007 05:17:35 +0000 (01:17 -0400)
committerJason Woofenden <jason183@herkamire.com>
Fri, 14 Sep 2007 05:17:35 +0000 (01:17 -0400)
encode.php
file_run.php

index 243b21f..1cbac74 100644 (file)
@@ -51,6 +51,18 @@ function enc_html($str) {
 }
 
 
+# Encode for output in html. Converts newlines to <br />
+#
+# Example: <p>~foo.html~</p>
+function enc_htmlbr($str) {
+       $str = str_replace('&', '&amp;', $str);
+       $str = str_replace('<', '&lt;', $str);
+       $str = str_replace('>', '&gt;', $str);
+       $str = str_replace("\n", "<br />\n", $str);
+       return $str;
+}
+
+
 # HTML attribute.
 #
 # Example: <input name="foo" value="~foo.attr~">
@@ -108,6 +120,17 @@ function enc_states($str) {
        return encode_options($str, $states_assoc, $use_keys = true);
 }
 
+# display <option>s
+function enc_provinces($str) {
+       $provinces_assoc = array("AB" => "Alberta", "BC" => "British Columbia", "MB" => "Manitoba", "NF" => "Newfoundland", "NB" => "New Brunswick", "NS" => "Nova Scotia", "NT" => "Northwest Territories", "NU" => "Nunavut", "ON" => "Ontario", "PE" => "Prince Edward Island", "QC" => "Quebec", "SK" => "Saskatchewan", "YT" => "Yukon Territory");
+       $ret = '';
+
+       return encode_options($str, $provinces_assoc, $use_keys = true);
+}
+
+
+
+
 
 define('PULLDOWN_ARRAY', 0); define('PULLDOWN_HASH', 1); define('PULLDOWN_2D', 2);
 
index 409cb4b..bca5c18 100644 (file)
 #
 # the file db_password.php would be like so:
 #
-#     function db_password() {
+#     function db_password_main() {
 #           return array('me', 'secret');
 #     }
 
 function file_run($filename) {
-    require_once($filename);
-    ereg_replace('.*/', '', $filename);
-    $func = basename($filename, '.php');
-    return $func();
+       require_once($filename);
+       $func = basename($filename, '.php') . '_main';
+       if(!function_exists($func)) {
+               $func = basename($filename, '.php');
+       }
+
+       return $func();
 }
 
 ?>