0

我需要三个 PHP 函数来优化这段代码,加速,请帮我这是我用于 PHP 分类网站的所有函数,

brandwords - 如果有人输入品牌,则提供更多详细信息

clean_url - 用于清除 URL 中不需要的字符,所有 clean_title - 用于清除 Title 中不需要的字符,所有

    function brandwords( $in ) {
        $wordToFind =  array(
           'suzuki' => 'Suzuki' , 
           'Toyota' => 'Toyota',
           -------------------------------- big database. 
        );

        $words = preg_split('/\s+/', remove_numbers(strtolower(trim($in))));

        foreach ( $wordToFind  as $key => $value ) {
           if ( ( $pos = array_search( strtolower( $key ), $words ) ) !== FALSE ) {
               return $value;
               exit();
           } 

           -----------------------------------------------------------------------
           function clean_url( $text ) {
           $text = strtolower( trim( $text ) );
           $code_entities_match = array(' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
           $code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
           $text = str_replace($code_entities_match, $code_entities_replace, $text);
           $text = str_replace('/[^a-zA-Z0-9\-]/', '-', $text);
           $text = str_replace('/^[\-]+/', '', $text);
           $text = str_replace('/[\-]+$/', '', $text);
           $text = str_replace('/[\-]{2,}/', '-', $text);
           $code_entities_match1 = array('--','---','----');
           $code_entities_replace1 = array('-','-','-');
           $text = str_replace($code_entities_match1, $code_entities_replace1, $text);
           return $text; 
           //$text2 = ucfirst(str_replace('-',' ',$text1)); 
        }

----------------------------------------------------------------
        function clean_title( $text ) {
           $text = strtolower( trim( $text ) );
           $code_entities_match = array('          ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
           $code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
           $text = str_replace($code_entities_match, $code_entities_replace, $text);
           $text = str_replace('/[^a-zA-Z0-9\-]/', '-', $text);
           $text = str_replace('/^[\-]+/', '', $text);
           $text = str_replace('/[\-]+$/', '', $text);
           $text = str_replace('/[\-]{2,}/', '-', $text);
           $code_entities_match1 = array('--','---','----');
           $code_entities_replace1 = array('-','-','-');
           $text = str_replace($code_entities_match1, $code_entities_replace1, $text);
           $text = ucfirst(str_replace('-',' ',$text));
           return $text; 
        }
    -------------------------------------------------------------
            function clean_desc( $text ) {
           $text = strtolower( trim( $text ) );
           $code_entities_match = array('.','/','\r','\n',' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",'.','/','*','+','~','`','=');
           $code_entities_replace = array(' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-',' ',' ',' ',' ',' ');
           $text = str_replace($code_entities_match, $code_entities_replace, $text);
           $text = str_replace('/[^a-zA-Z0-9\-]/', '-', $text);
           $text = str_replace('/^[\-]+/', '', $text);
           $text =  str_replace('/[\-]+$/', '', $text);
           $text = str_replace('/[\-]{2,}/', '-', $text);   
           //$text = preg_replace("'\b[a-z0-9]{1,3}\b'i",' ',$text);
           $code_entities_match1 = array('--','---','----');
           $code_entities_replace1 = array('-','-','-');
           $text = str_replace($code_entities_match1, $code_entities_replace1, $text);
           $text = ucfirst(str_replace('-',' ',$text));
           return $text; 
        }       

4

0 回答 0