网站出现illegal string offset 错误的解决办法

出现此错误是因为循环的值$w里有空数组,可在foreach循环内加if判断是否是数组,如:

    foreach($ws as $w) {
      if(is_array($w)){
	      $w = trim($w);
	      if(strlen($w)<2) continue;
	      if(!preg_match("/[^0-9:-]/",$w)) continue;
	      if(strlen($w)==2&&ord($w[0])>0x80) continue;
	      if(isset($wks[$w])) $wks[$w]++;
	      else $wks[$w] = 1;
      }
}

猜你喜欢

转载自blog.csdn.net/qq_38882327/article/details/89378183