strpos():参数 #2 ($needle) 必须是字符串类型,数组给定 [重复]

问题描述 投票:0回答:1

嗨,

我有这个代码:

if ( strpos( $_GET[ 'y' ], array( '/', '.', '\\', '%', '#', ';' ) ) === false

它在 php5 上工作正常但现在在 php 8 上我得到这个错误:

 strpos(): Argument #2 ($needle) must be of type string, array given

我必须完全摆脱那条线还是有其他解决办法?

谢谢。

php strpos
1个回答
0
投票

如果您阅读文档https://www.php.net/manual/en/function.strpos.php您会看到两个参数都必须是字符串(正如错误实际上告诉您的那样)。

如果您想搜索多个刺痛,请使用正则表达式

preg_match()

或在线搜索多针strpos。它甚至在 stack overflow strpos() with multiple needles? 或者这里 Using 2 or more needle when using strpos

希望这有帮助;)

© www.soinside.com 2019 - 2024. All rights reserved.