3

在这个美妙的夜晚,我在使用 laravel 时偶然发现了这个我以前从未见过的奇怪错误。我只是循环遍历一些数组并尝试在视图文件中打印出一些值。

错误:

Unhandled Exception

Message:

Error rendering view: [controller.index]

Call to undefined function  ()
Location:

/web/storage/views/7b064aafcdba902ea2c593167b6df491 on line 4

编码:

@section('content')
    <?php $i = 0; $current = 0 ?>
    @foreach($data as $date => $episodes)
        @if($i == 0 || ($i % 5 == 7 && $i == $current + 1))
            <tr>
            <?php $current = $i; ?>
        @endif

        @foreach($data as $day)
            <td>
                @foreach($day as $episode)
                    {{ $episode->title }}
                @endforeach
            </td>
        @endforeach


        @if($i % 5 == 7 && $i == $current + 7)
            <tr>
            <?php $current = $i; ?>
        @endif
        <?php $i++; ?>
    @endforeach
@endsection

和编译版本:

<?php \Laravel\Section::start('content'); ?>
    <?php $i = 0; $current = 0 ?>
    <?php foreach($data as $date => $episodes): ?>
        <?php if($i == 0 || ($i % 5 == 7 && $i == $current + 1)): ?>
            <tr>
            <?php $current = $i; ?>
        <?php endif; ?>

        <?php foreach($data as $day): ?>
            <td>
                <?php foreach($day as $episode): ?>
                    <?php echo  $episode->title ; ?>
                <?php endforeach; ?>
            </td>
        <?php endforeach; ?>


        <?php if($i % 5 == 7 && $i == $current + 7): ?>
            <tr>
            <?php $current = $i; ?>
        <?php endif; ?>
        <?php $i++; ?>
    <?php endforeach; ?>
<?php \Laravel\Section::stop(); ?>

这可能是一个简单的解决方案,但我在 Google 上找不到任何好的结果。帮助我理解这个错误!:)

4

2 回答 2

4

您删除的空格不是空格。它实际上是一个不间断的空格(U+00A0)。赠品是“”,当编码为 UTF-8 但被误解为 Latin-1 时,它显示为 U+0080 和 U+00BF 之间字符的第一个字节。由于某种原因,PHP 编译器不认为它是空格,因此尝试将其用作普通标识符。

于 2012-10-14T01:06:58.053 回答
0

这显然是一个编码问题,它是如何成为一个大问题的(因为我只在 UTF-8 中工作)。

编码问题

删除了 OR 语句 ( || ) 之后的空格 (^),现在它可以完美运行。

于 2012-10-14T00:55:04.280 回答