PHP 7.3 strpos()针问题?

时间:2019-07-09 01:07:48

标签: php search strpos

错误: strpos():将来,非字符串针将被解释为字符串。使用显式的chr()调用将当前行为保留在

已经阅读了许多在线主题-他们似乎都没有触及到我如何编写代码,这使我不确定自己在哪里错了。

此代码使用get搜索文本文件,并通过该搜索返回文件数组。代码一直工作到7.3更新。

--------------------------------------------------------------------------- AssertionError                            Traceback (most recent call last) <ipython-input-8-224b99f63642> in <module>
      4 image_np = skimage.transform.resize(image_np,(224,224))
      5 #image_np = np.expand_dims(image_np, axis=0)
----> 6 preds = [model.do_test(polySess, image_np, top_k) for top_k in range(_FIRST_TOP_K)]
      7 
      8 # sort predictions based on the eval score to pick the best.

<ipython-input-8-224b99f63642> in <listcomp>(.0)
      4 image_np = skimage.transform.resize(image_np,(224,224))
      5 #image_np = np.expand_dims(image_np, axis=0)
----> 6 preds = [model.do_test(polySess, image_np, top_k) for top_k in range(_FIRST_TOP_K)]
      7 
      8 # sort predictions based on the eval score to pick the best.

~/Desktop/polyrnn/src/PolygonModel.py in do_test(self, sess, input_images, first_top_k)
     61         Return polygon
     62         """
---> 63         assert input_images.shape[1:] == (224, 224, 3), 'image must be rgb 224x224 (%s)' % str(input_images.shape)
     64         pred_dict = sess.run(
     65             self._prediction(),

AssertionError: image must be rgb 224x224 ((224, 224, 4))

$ search_get在这里无效吗?

1 个答案:

答案 0 :(得分:1)

@ paul-t是正确的,您正在分配变量而不是将其与null进行比较,这就是为什么您应该使用所谓的Yoda conditions

if (null === $search_get) {
    $search_get = 'encyclopedia';
}

无论如何,这是代码的稍微简化的版本:

$search_get = @$_GET['q'] ?: 'encyclopedia';

foreach (glob("dir/*.txt") as $search) {
    $contents = file_get_contents($search);
    if (!empty($contents) && false !== strpos($contents, $search_get)) {
        $found[] = $search;
    }
}

BTW考虑使用stripos代替strpos,因为当前对$contents变量的检查区分大小写。