2010-06-30 67 views
1

下面的函數check_porn_terms檢查一個變量是否包含不適合家庭使用的條件,如果它包含,則將用戶重定向回主頁面。一次可以在一個函數中使用兩個變量嗎?

如下所列,它檢查變量$title是否有不適合家庭使用的術語。我想對另一個變量$cleanurl執行此檢查。我可以用check_porn_terms($title, $cleanurl)或其他類似的東西替換下面的check_porn_terms($title)嗎?如果不是,我該怎麼做?

由於提前,

約翰

if(!check_porn_terms($title)) 
{ 

    session_write_close(); 
    header("Location:http://www.domain.com/index.php"); 
    exit; 

} 
+0

爲什麼不使用數組? – Cristian 2010-06-30 19:02:29

回答

2

你只需要調用函數兩次(結合「或」 ||運營商)來檢查每個變量:

if(!check_porn_terms($title) || !check_porn_terms($cleanurl)) 
{ 
    session_write_close(); 
    header("Location:http://www.domain.com/index.php"); 
    exit; 
} 
2

如果你寫的函數自己,它重新定義check_porn_terms()(無參數),然後在函數內部,環比func_get_args並檢查是否每個爭論是「乾淨的」。

但是,如果你願意的話,你可以用兩個參數來代替。我的觀點是,爲什麼要停在兩點?讓它採取任何數量的論據。

當你在它的時候,你可以嘗試實際閱讀頁面,並掃描整個頁面的髒話。

0

如果你想在其他參數傳遞給check_porn_terms,你需要重新定義函數

function check_porn_terms($first_term, $second_term) 
{ 
    //code to check both terms here 
} 

你也可以重寫函數接受參數數組,然後foreach他們,或者得到與func_get_args()真正看中

你可能想要做什麼,並且不需要重新定義函數能做的,就是調用函數兩次

// the || means "or" 
if(!check_porn_terms($title) || !check_porn_terms($cleanurl)) 
{ 
} 
相關問題