php 函数 split() 已弃用并爆炸 ....未定义的偏移量:1 E_NOTICE 文件中的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36370456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
function split() deprecated and explode ....Undefined offset: 1 E_NOTICE Error in file
提问by selemo
I received this error: function split() deprecated
我收到此错误: function split() deprecated
list ($kk, $vv) = split( ' ', $buf, 2);
When I replaced it with explode
or preg_split
I got this error Undefined offset: 1 E_NOTICE Error in file
当我将其替换为explode
或preg_split
出现此错误时 Undefined offset: 1 E_NOTICE Error in file
list ($kk, $vv) = explode( " ", $buf, 2);
This is the full code
这是完整的代码
function get_toprotatingbanners()
{
$s = array ();
$file = fopen ('inc/adsadmin/toprotatingbanners.php', 'r');
if ($file)
{
while ($buf = fgets ($file, 20000))
{
$buf = chop ($buf);
if (($buf != '<?/*' AND $buf != '*/?>'))
{
list ($kk, $vv) = explode(" ", $buf, 2);
$s[$kk] = $vv;
continue;
}
}
}
fclose ($file);
return $s;
}
Please help me.
请帮我。
回答by alexeevyci
Function split is deprecated "This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0." as you can see on php.net/manual/en/function.split.php
不推荐使用函数拆分“此函数在 PHP 5.3.0 中已弃用,在 PHP 7.0.0 中已删除。” 正如你在php.net/manual/en/function.split.php上看到的
Undefined offset: 1 is because $buf is undeffined.
未定义偏移量:1 是因为 $buf 未定义。
回答by Harendra Singh
Warning This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.
警告 该函数在 PHP 5.3.0 中被弃用,在 PHP 7.0.0 中被移除。
Alternatives to this function include:
此功能的替代方案包括:
preg_split()
explode()
str_split()