在 split() 调用附近,“解析错误:语法错误,意外的 T_VARIABLE”

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

当我尝试启动 PHP 脚本时,出现此错误:

[错误] [客户端 ::1] PHP 解析错误:语法错误,/var/www/loterija.php 第 16 行出现意外的 T_VARIABLE

我认为问题出在

split()
函数上。这是代码:

<?php
$arr = array();
if (isset($_POST['roll'])):
    echo "Lucky numbers: " . '<br />';

    for ($i = 1; $i <= 5; $i++) {
        $arr[] = rand(1, 100);
    }

    $post = $_POST['numbers'];
    
    echo '<br />' . "Your numbers: " . '<br />'; 
    $split = split(" ", $post, 5);   
endif;
?>

<html>
<head>
    <title>Lottery Script</title>
</head>
<body>
    <form action="#" method="post">
        Enter five numbers: <input type="text" name="numbers" />
        <input type="submit" name="roll" value="Roll!" />
    </form>
</body>
</html>
php parse-error
3个回答
1
投票

拆分已弃用,请使用爆炸。您使用什么版本的 PHP。如果是5.0以上就用explode。

我假设你们被空间分开了。

http://php.net/manual/en/function.explode.php


0
投票

没有理由使用

split()
,它已被弃用。
只需这样做:
$split = explode(" ", $post);


0
投票

考虑

preg_split
explode

http://us.php.net/manual/en/function.split.php

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