1

我有一个php,如果它返回一个错误,这个错误:解析错误:语法错误,意外'=',包含此代码的行:$result -= 'tm_year' = 1900;有人知道如何解决这个问题吗?

if (!function_exists( 'strptime' )) {
        function strptime($strdate, $format) {
            $plop = array( 's' => 'tm_sec', 'i' => 'tm_min', 'H' => 'tm_hour', 'd' => 'tm_mday', 'm' => 'tm_mon', 'Y' => 'tm_year' );
            $regexp = preg_quote( $format, '/' );
            $regexp = str_replace( array( '%d', '%m', '%Y', '%H', '%i', '%s' ), array( '(\d{2})', '(\d{2})', '(\d{4})', '(\d{2})', '(\d{2})', '(\d{2})' ), $regexp );

            if (preg_match( '/^' . $regexp . '$/', $strdate, $m )) {
                $result = array( 'tm_sec' => 0, 'tm_min' => 0, 'tm_hour' => 0, 'tm_mday' => 0, 'tm_mon' => 0, 'tm_year' => 0, 'tm_wday' => 0, 'tm_yday' => 0, 'unparsed' => '' );
                preg_match_all( '/%(\w)/', $format, $patt );
                foreach ($patt[1] as $k => $v) {
                    if (!isset( $plop[$v] )) {
                        continue;
                    }

                    $result[$plop[$v]] = intval( $m[$k + 1] );

                    if ($plop[$v] == 'tm_mon') {
                        $result -= $plop[$v] = 1;
                        continue;
                    }
                }

                $result -= 'tm_year' = 1900;
                return $result;
            }

            return false;
        }
    }
4

1 回答 1

2

'tm_year' 是您尝试为其分配值 1900 的字符串。你不能这样做,因此错误。似乎是在编写速记代码时试图变得太可爱,因为老实说,您无法说出您的意图是什么。

于 2013-01-29T23:31:43.747 回答