0

このコードを最適化するために必要な 3 つの 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