PHP Warning: sscanf(): Different numbers of variable names and field specifiers in...

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/asty9000/article/details/82635217

在使用字符串解析函数sscanf时可能会遇到警告:PHP Warning:  sscanf(): Different numbers of variable names and field specifiers in...,比如:

<?php
$str="Hello world!";
$format="%s %s";
echo sscanf($str,$format,&$result)."\n";
echo $result;
?>

这是由于解析的结果数量与传入的引用参数数量不一致造成的。只需要根据解析的结果数量传入引用参数即可,修改后:

<?php
$str="Hello world!";
$format="%s %s";
echo sscanf($str,$format,&$result,&$another)."\n";
echo $result."\n";
echo $another."\n";
?>

这样就不会产生告警了。

猜你喜欢

转载自blog.csdn.net/asty9000/article/details/82635217