我需要三个PHP函数来优化这段代码,加速,请帮助 这个我用于PHP分类网站的所有功能,
品牌 - 如果有人进入品牌,则会提供更多细节
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(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$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(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$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',' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",'.','/','*','+','~','`','=');
$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;
}