[pLog-svn] r2850 - plog/trunk/class/data

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Tue Jan 24 03:07:45 GMT 2006


Author: jondaley
Date: 2006-01-24 03:07:43 +0000 (Tue, 24 Jan 2006)
New Revision: 2850

Modified:
   plog/trunk/class/data/textfilter.class.php
Log:
new function domainize() for the domain side of URLs.  They should be treated different than the path side, mainly because underscores aren't allowed, but probably for other reasons that will come up later

Modified: plog/trunk/class/data/textfilter.class.php
===================================================================
--- plog/trunk/class/data/textfilter.class.php	2006-01-24 01:09:50 UTC (rev 2849)
+++ plog/trunk/class/data/textfilter.class.php	2006-01-24 03:07:43 UTC (rev 2850)
@@ -416,6 +416,41 @@
             return $string;            
         }
 		
+
+        /** 
+         * Given a string, convert it into something that can be used in the domain part of a URL
+         * (it probably doesn't work very
+         * well with non iso-8859-X strings) It will remove the following characters:
+         *
+         * ; / ? : @ & = + $ ,
+         *
+         * It will convert accented characters such as ˆ, , ’, etc to
+         * their non-accented counterparts (a, e, i) And
+         * any other non-alphanumeric character that hasn't been removed
+         * or replaced will be thrown away.
+         *
+         * @param string The string that we wish to convert into something that can be used as a URL
+         */
+        function domainize( $string )
+        {
+		    // remove unnecessary spaces and make everything lower case
+		    $string = preg_replace( "/ +/", " ", strtolower($string) );
+
+            // removing a set of reserved characters (rfc2396: ; / ? : @ & = + $ ,)
+            $string = str_replace(array(';','/','?',':','@','&','=','+','$',','), '', $string);
+
+            // replace some characters to similar ones
+            $search  = array('_',' ','ä','ö','ü','é','è','à','ç','à','è','ì','ò','ù','á','é','í','ó','ú','ë','ï');
+            $replace = array('-','-','a','o','u','e','e','a','c','a','e','i','o','u','a','e','i','o','u','e','i');
+            $string = str_replace($search, $replace, $string);
+            
+            // and everything that is still left that hasn't been replaced/encoded, throw it away
+            $string = preg_replace( '/[^a-z0-9.-]/', '', $string );
+            $string = trim($string, "-.");
+            
+            return $string;            
+        }
+
 		/**
 		 * xhtml-izes a string. It uses the KSes filter for the task as long as the configuration parameter
 		 * xhtml_converter_enabled is enabled. If xhtml_converter_aggreesive_mode_enabled is also enabled,



More information about the pLog-svn mailing list