Ingore案例敏感性在php中使用substr_count时



我正在制作一个单词计数器程序,因此,如果用户在文本框中键入像(" hello")的单词并提交表单(HTML),则该程序将搜索并计数它出现在特定网页上的次数。
我有这个代码,是西班牙语,所以我会为您磨砂。

<?php
/*if the user submit, do this...*/ 
if(isset($_POST["submit"])) {
/*no warnings*/ 
error_reporting(E_ALL ^ E_WARNING); 
$buscar = $_POST["texto"];
$pagina = $_POST["Web"];
$buscar2 = strtolower($buscar);
/*no special characters like !hello!*/
$buscar2 = preg_replace("/[^A-Za-z0-9]/", "", $buscar2);
/*if the webpage doesn't exist, display this message*/
$headers = @get_headers($pagina);
if(strpos($headers[0],'200')===false)
{echo "Página no válida.";}else{ 
/*Get all content from the webpage*/
$web = file_get_contents($pagina);
/*Word - count the number of times it appears on a webpage*/
$result = (substr_count(strip_tags($web), $buscar2));
/*Display results*/
if($result == 0){
echo "La palabra " .strtoupper($buscar2). " no aparece";   
}else{
echo "La palabra " .strtoupper($buscar2). " aparece: $result veces";
}
}
}
?>

我的问题是,当您在网页上搜索时,可以忽略案例, 例如:Hello-Hello-Hello相同。

如果您想要一个不敏感的substr_count功能,为什么不使用strtolower以情况不变形式转换输入。

$count = substr_count(strtolower($haystack), strtolower($needle));

无法本地执行此操作。我只需要这样做:

substr_count(strtolower($haystack), strtolower($needle));

最新更新