开发者

PHP to compare and return a variable in a querystring

I need a bi开发者_开发百科t 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.


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


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 ...

.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜