1

我有一个数组,我想知道它是否包含特定的单词,例如 microsoft-iis 7.5?

Array
(
[0] => HTTP/1.1 302 Found
[1] => Cache-Control: no-cache, no-store, must-revalidate, no-transform
[2] => Pragma: no-cache
[3] => Content-Length: 340
[4] => Content-Type: text/html; charset=utf-8
[5] => Expires: -1
[6] => Server:microsoft-iis 7.5
)

谢谢

4

4 回答 4

1
$stack = Array(
          '0' => 'HTTP/1.1 302 Found',
          '1' => 'Cache-Control: no-cache, no-store, must-revalidate, no-transform',
          '2' => 'Pragma: no-cache',
          '3' => 'Content-Length: 340',
          '4' => 'Content-Type: text/html; charset=utf-8',
          '5' => 'Expires: -1',
          '6' => 'Server:microsoft-iis 7.5'
);

$contain = substr_count ( implode( $stack ), 'microsoft-iis 7.5' )?'string found':'string not found';

echo $contain;
于 2012-07-20T17:52:39.823 回答
1
if(array_walk($array, function($str){ return strstr($str, 'microsoft-iss 7.5'); })){
    echo "array_matches";
}
于 2012-07-20T17:43:18.613 回答
1

如果您只想知道字符串是否存在,您可以对内爆字符串运行 stripos:

if (false !== stripos(implode("\n", $headers), "microsoft-iis"))
{
   // ...
}

(或 strpos 如果您想要区分大小写)。

于 2012-07-20T17:45:24.627 回答
0

您可以迭代数组并使用substr_count进行检查。它将返回您的搜索字符串出现的次数

foreach ($your_array as $values){
$occurrence = substr_count($values,'microsoft-iis 7.5') ? 'exists' : 'does not exist';
    echo $occurrence;
}
于 2012-07-20T17:41:10.987 回答