2010-06-30 66 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)) 
{ 
} 
相关问题