Php 如何回显数组中与给定字符串匹配的值

Php 如何回显数组中与给定字符串匹配的值,php,arrays,Php,Arrays,我需要帮助我的PHP代码 我想回显数组$find中与给定字符串匹配的字符串 例如,如果我输入“https://amazon.com/“结果将是: !Found - [ https://amazon.com/ ] - [ 2 keywords was found in the site. [Which word / words from $finds was found.] ] 这是我的实际代码: $ii = [ 'cookie' => mt_rand().'.txt' ]; if (

我需要帮助我的PHP代码

我想回显数组
$find
中与给定字符串匹配的字符串

例如,如果我输入“https://amazon.com/“结果将是:

!Found - [ https://amazon.com/ ] - [ 2 keywords was found in the site. [Which word / words from $finds was found.] ]
这是我的实际代码:

$ii = [
'cookie' => mt_rand().'.txt'

];

if (!is_dir($pathhhhhh)) {  
    mkdir($pathhhhhh, 0777, true);
}
$d1 = getcwd();
$d = str_replace('\\', '/', $d1);

$g = curl_init();
curl_setopt($g, CURLOPT_COOKIEJAR, "".$d."/COOKIE/".$ii['cookie']."");
curl_setopt($g, CURLOPT_COOKIEFILE, "".$d."/COOKIE/".$ii['cookie']."");
curl_setopt($g, CURLOPT_URL, ''.$hehe.'');
curl_setopt($g, CURLOPT_HTTPGET, 1);
curl_setopt($g, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($g, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($g, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($g, CURLOPT_SSL_VERIFYHOST, 0);
$g1 = curl_exec($g);
$string = html_entity_decode(htmlentities($g1));
$finds = ['shop'];
$findCount = 0;


foreach ($finds as $find) {
    if ( stripos($string, $find) !== false ) $findCount++;
}

if ($findCount != 0){
    if($findCount > 1){
        $ident = 'Keywords';
    }else{
        $ident = 'Keyword';
    }
    $res = "!Found - [$hehe] - [ $findCount $ident was found in the site. ]";
    echo "<font size='4' color='#39ff14'><tt><i>$res</tt></i></font><br>";

} 
elseif (empty($string)) {
    $res = "!Error - [$hehe] - [ An error occurred during the scraping. ]";
    echo "<font size='4' color='#ff073a'><tt><i>$res</tt></i></font><br>";
} 
else {
    $res = "!Error - [$hehe] - [ No Match Found ]";
    echo "<font size='4' color='#ff073a'><tt><i>$res</tt></i></font><br>"; 
}
$ii=[
'cookie'=>mt_rand()..txt'
];
如果(!is_dir($pathhhhh)){
mkdir($pathhhhhh,0777,true);
}
$d1=getcwd();
$d=str\U替换(“\\\”、“/”、$d1);
$g=curl_init();
curl_setopt($g,CURLOPT_COOKIEJAR,“$d.”/COOKIE/“$ii['COOKIE]”);
curl_setopt($g,CURLOPT_COOKIEFILE,“$d.”/COOKIE/“$ii['COOKIE]”);
curl_setopt($g,CURLOPT_URL,“.$hehe.”);
curl_setopt($g,CURLOPT_HTTPGET,1);
curl_setopt($g,CURLOPT_RETURNTRANSFER,1);
curl_setopt($g,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($g,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($g,CURLOPT_SSL_VERIFYHOST,0);
$g1=旋度执行($g);
$string=html_entity_decode(htmlentities($g1));
$finds=['shop'];
$findCount=0;
foreach($finds as$find){
if(stripos($string,$find)!==false)$findCount++;
}
如果($findCount!=0){
如果($findCount>1){
$ident='Keywords';
}否则{
$ident='Keyword';
}
$res=“!在站点中找到了-[$HEHEHE]-[$findCount$ident.]”;
回声“$res
”; } elseif(空($string)){ $res=“!Error-[$hehe]-[刮片过程中发生错误。]”; 回声“$res
”; } 否则{ $res=“!错误-[$hehe]-[未找到匹配项]”; 回声“$res
”; }
您可以在数组中添加
$find
,然后使用
内爆()
输出这些单词

$hehe = 'example.com';
$string = "A sample sentence with words like shop.";

$finds = ['shop'];
$founds = [];

foreach ($finds as $find) {
    if ( stripos($string, $find) !== false ) {
        $founds[] = $find;
    }
}



if (!empty($founds)) {
    $findCount = count($founds);
    if ($findCount > 1){
        $ident = 'Keywords';
    }
    else {
        $ident = 'Keyword';
    }
    $words = implode(', ', $founds);
    $res = "!Found - [$hehe] - [ $findCount $ident was found in the site : $words]";
    echo "<font size='4' color='#39ff14'><tt><i>$res</tt></i></font><br>";
} 

请将代码作为文本而不是图像发布。请阅读并完成。对不起,我是stackoverflow的新手。不清楚问题是什么,也不清楚您的要求是什么。请给出输入和期望输出值的完整示例。您必须小心。例如,在句子中搜索
sent
,将得到一个匹配(
句子
)。
!Found - [example.com] - [ 1 Keyword was found in the site. shop]