我目前有一个问题.我有一个看起来像下面的代码,我想要一个运算符,检查查询的一部分是否存在于数组中.这是我的代码:
<?php
$search = 'party hat';
$query = ucwords($search);
$string = file_get_contents('http://clubpenguincheatsnow.com/tools/newitemdatabase/items.php');
$string = explode('<br>',$string);
foreach($string as $row)
{
preg_match('/^(\D+)\s=\s(\d+)\s=\s(\D+)\s=\s(\d+)/', trim($row), $matches);
if($matches[1] == "$query")
{
echo "<a href='http://clubpenguincheatsnow.com/tools/newitemdatabase/info.php?id=$matches[2]'>";
echo $matches[1];
echo "</a><br>";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我想要做的不是if($matches[1] == "$query")检查两者是否相同,我希望我的代码看看是否$query存在PART $matches[1].我怎么做呢?请帮我!
您可以strpos用来测试字符串是否包含在另一个字符串中:
if(strpos($matches[1], $query) !== false)
Run Code Online (Sandbox Code Playgroud)
如果您希望它不区分大小写,请stripos改用.