网站出现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;
      }
}

你可能感兴趣的:(网站问题)