iliaa           Mon May 24 16:09:17 2004 EDT

  Modified files:              
    /livedocs   handlers.php 
  Log:
  Optimization tune-up.
  
  
http://cvs.php.net/diff.php/livedocs/handlers.php?r1=1.6&r2=1.7&ty=u
Index: livedocs/handlers.php
diff -u livedocs/handlers.php:1.6 livedocs/handlers.php:1.7
--- livedocs/handlers.php:1.6   Sat May  1 15:58:13 2004
+++ livedocs/handlers.php       Mon May 24 16:09:17 2004
@@ -18,7 +18,7 @@
 // | Special Handlers for $aliases                                        |
 // +----------------------------------------------------------------------+
 //
-// $Id: handlers.php,v 1.6 2004/05/01 19:58:13 nlopess Exp $
+// $Id: handlers.php,v 1.7 2004/05/24 20:09:17 iliaa Exp $
 
 
 /***********************************
@@ -63,8 +63,8 @@
        echo "</div><hr />\n";
 
        /* Sanitize index letter */
-       if (isset($_GET['i']) && preg_match('/^[A-Z]{0,1}$/i', $_GET['i'])) {
-               $idxl = $_GET['i'];
+       if (isset($_GET['i']) && ctype_alpha($_GET['i'][0])) {
+               $idxl = $_GET['i'][0];
        } else {
                $idxl = 'a';
        }
@@ -74,22 +74,16 @@
        sqlite_create_function($idx, 'TO_LOWER', 'strtolower');
 
        /* Select all titles starting with $idxl */
-       $q = sqlite_query($idx, "SELECT title, id FROM idents WHERE STARTS_WITH(title, 
'$idxl') ORDER BY TO_LOWER(title)");
-       if ($q) {
-               while ($r = sqlite_fetch_array($q, SQLITE_NUM)) {
-                       list($title, $id) = $r;
-                       $url = FORCE_DYNAMIC ? "?l=$lang&q=$id#$id" : "$lang/$id#$id";
-                       echo "<span class='index'><a href='" . WEBBASE . 
"$url'>$title</a></span><br />\n";
-               }
+       $q = sqlite_array_query($idx, "SELECT title, id FROM idents WHERE 
STARTS_WITH(title, '$idxl') ORDER BY TO_LOWER(title)", SQLITE_NUM);
+       foreach ($q as $r) {
+               list($title, $id) = $r;
+               $url = FORCE_DYNAMIC ? "?l=$lang&q=$id#$id" : "$lang/$id#$id";
+               echo "<span class='index'><a href='" . WEBBASE . 
"$url'>$title</a></span><br />\n";
        }
 }
 
-function sqlite_starts_with($title, $char) {
-       $title = strtolower($title);
-       $char  = strtolower($char);
-       if (!strlen($title) || !strlen($char)) {
-               return FALSE;
-       }
-       return ($title{0} == $char{0});
+function sqlite_starts_with($title, $char)
+{
+       return !strncasecmp($title, $char, 1);
 }
 ?>

Reply via email to