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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:47:30  来源:igfitidea点击:

function split() deprecated and explode ....Undefined offset: 1 E_NOTICE Error in file

phpsplitundefinedoffsetdeprecated

提问by selemo

I received this error: function split() deprecated

我收到此错误: function split() deprecated

list ($kk, $vv) = split( '  ', $buf, 2);

When I replaced it with explodeor preg_splitI got this error Undefined offset: 1 E_NOTICE Error in file

当我将其替换为explodepreg_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()