函数被打印两次
我做了这个函数,相同的结果被打印两次。知道为什么吗?这是我的职责吗?我找不到任何问题。
$valid 是一个数组。
function validOutput($output, $valid, $name, $mirror){
foreach($valid as $e) {
if(strpos($output, $e) != false) {
echo '<br />' . $name . '<br />';
echo '<textarea cols=100 rows=10>';
echo '[tab: Mirror' . $mirror . ']';
echo $output;
echo "</textarea>";
}
}
}
如果您发现有什么问题请告诉我,谢谢。
编辑:
$valid = array("facebook", "fbcdn", "megavideo", "video", "videoweed", "4shared");
I made this function, the same result get printed twice. Any idea why? is it my function? I can't find anything wrong with it.
$valid is an array.
function validOutput($output, $valid, $name, $mirror){
foreach($valid as $e) {
if(strpos($output, $e) != false) {
echo '<br />' . $name . '<br />';
echo '<textarea cols=100 rows=10>';
echo '[tab: Mirror' . $mirror . ']';
echo $output;
echo "</textarea>";
}
}
}
Please tell me if you see anything wrong with it, thanks.
Edit:
$valid = array("facebook", "fbcdn", "megavideo", "video", "videoweed", "4shared");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$valid
有两个元素,它们是$output
的子字符串您能显示一些示例输入吗?也许可以解释一下
$valid
参数背后的动机是什么?$valid
has two elements that are substrings of$output
Can you show some sample inputs? Maybe explain what the motivation behind the
$valid
parameter is?我不知道这是否是问题所在,但
strpos()
必须检查为=== false
或!== false
,因为strpos
可能是0
并且它将被视为false
。文档> http://php.net/manual/en/function.strpos.php
I don't know if that could be the problem, but
strpos()
must be checked as=== false
or!== false
, becausestrpos
could be0
and it will be treated asfalse
.Doc > http://php.net/manual/en/function.strpos.php