HEREDOC 语法 PHP 第一行出错

HEREDOC syntax PHP erroring on first line

我正在尝试用 Nowdoc 语法编写以下代码,但直接在 $str = <<<HTML

我在第一行有错误。我不知道为什么。我在另一个项目中使用它并且很好。

$str = <<<HTML
    <div>
        <div class="product-thumb">
            <div class="ribbon">
                <img src="/img/affiliate.png"  alt=""/> 
            </div>

            <a href="">
                <header class="product-header">
                    img  
                </header>
                <div class="product-inner">
                    <h5 class="product-title">client name</h5>
                    <div class="product-meta">
                        <ul class="product-price-list">
                            <li><span class="product-save">saving</span></li>
                        </ul>
                    </div>
                    <p class="product-location"><i class="fa fa-map-marker"></i> cat</p>
                </div>
            </a>
        </div>
    </div>
HTML;

我收到以下错误

Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in

文件结束意味着脚本在该部分之前有 a ?>,脚本快死了,或者你在 $str 之前有相同的隐藏字符。尝试删除 $str 之前的内容(即使您没有看到字符)。