PHP to compare and return a variable in a querystr

2019-08-02 23:31发布

I need a bit of simple PHP code that can return a specified variable if any one of three variables is contained within a query string. Probably easier to explain like this:

if {querystring} contains {var1} or {var2} or {var3} return {var1}

This is expands on the following question: Creating a canonical with PHP

I need to add said code to one of the variables specified in function params, in the linked question.

标签: php html xhtml
2条回答
祖国的老花朵
2楼-- · 2019-08-02 23:47
function evaluateThis($var1,$var2,$var3) {
   if((strpos($string,$var1) !== false) || (strpos($string,$var1) !== false) || (strpos($string,$var1) !== false)) {
       return $var1;
   }
   else { return 'string not found'; }
 }

Is this what you mean

查看更多
仙女界的扛把子
3楼-- · 2019-08-02 23:58

If you want to analyse the query string of the current request:

array_search($var1,$_GET)!==false OR array_search($var2,$_GET)!==false ....

else:

$vars = array();
parse_string($queryString,$vars);
if(array_search($var1,$vars)!==false OR array_search($var2,$vars)!==false ...

.

查看更多
登录 后发表回答