Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 警告:substr\u count():空子字符串_Php_Substring_Substr - Fatal编程技术网

Php 警告:substr\u count():空子字符串

Php 警告:substr\u count():空子字符串,php,substring,substr,Php,Substring,Substr,我突然收到了一个可怕的错误,说“空子字符串”指的是第8行 $score3 = substr_count($name_only, $text); 我不知道问题是什么,这是一个搜索功能。提交到搜索框中是否为空 我想可能是这样的,所以我用JS和HTML进行了更改,所以不可能提交空白或只有空格的搜索表单,但错误仍然存在 这是我的php,对任何比我有更好知识的人来说,有什么突出的问题来源吗 function search_now($images){ global $text, $scores, $s

我突然收到了一个可怕的错误,说“空子字符串”指的是第8行

$score3 = substr_count($name_only, $text);
我不知道问题是什么,这是一个搜索功能。提交到搜索框中是否为空

我想可能是这样的,所以我用JS和HTML进行了更改,所以不可能提交空白或只有空格的搜索表单,但错误仍然存在

这是我的php,对任何比我有更好知识的人来说,有什么突出的问题来源吗

function search_now($images){
  global $text, $scores, $scores2, $scores3, $do_search;
  $images2 = array();
  foreach ($images as $key => $value) {
    $name_only = $value['name'];
    similar_text($text, $name_only, $score);                        
    $score2 = substr_compare($name_only, $text, 0);
    $score3 = substr_count($name_only, $text);
    if($do_search){
      if($score<20)
      continue;
    }
    $images2[$key] = $value;
    $images2[$key]['score'] = $score;
    $images2[$key]['score2'] = $score2;
    $images2[$key]['score3'] = $score3;
    //$scores[$key] = ($do_search)? $score : $key;
    $scores[$key] = $score;
    $scores2[$key] = $score2;
    $scores3[$key] = $score3;
  }
  return $images2;
}
function search\u now($images){
全局$text、$scores、$scores2、$scores3、$do_search;
$images2=array();
foreach($key=>$value的图像){
$name_only=$value['name'];
类似文本($text,$name\u only,$score);
$score2=substr\u compare($name\u only,$text,0);
$score3=子项计数($name\u only,$text);
如果($do_search){

如果($score),则当
substr\u count()
的第二个参数是空字符串时会触发错误消息。如果转储
$text
,我想您会发现它是空字符串

不确定代码片段与其余代码的关系,但可以在函数中包含一个检查

if ($text == '') {
   // handle scoring differently
}