簡體   English   中英

解析錯誤:語法錯誤,意外的'<'-----當使用echo <<

[英]Parse error: syntax error, unexpected '<' -----when using echo <<<END ** END; -------

我花了2天的大部分時間來嘗試解決此問題,當我在本地計算機上加載以下代碼時,它可以正常工作;當我將以下代碼加載到雲上的真實站點時,它會提示此錯誤。

Parse error: syntax error, unexpected '<'

到達第74行時就會發生這種情況

73  <?php
74  echo <<<END
75  <p>$fullAddress<br />Phone:   

目前,我的網站已損壞,對您的幫助將不勝感激。

碼:

<?php
    $addressArray = array(
        $row->fldAddress1,
        $row->fldAddress2,
        $row->fldCity,
        $row->fldCounty,
        $row->fldPostcode
    );

    $fullAddress = implode(", ", array_filter($addressArray));

    $locationAsString = str_replace(array('-',"."), ' ', $row->location);
    $locationAsString = str_replace("ireland", "northern ireland", $locationAsString);

    $addressTeaser = $row->fldCity . ", " . $row->fldCounty . ", " . $row->fldPostcode . ", " . $locationAsString;

    $shopName = $row->fldShopNameTidy;
    $head = substr($shopName,0,1);
    $head = strtoupper($head);

    $storeHasWebsite = ($row->fldShopWebsite != "" && $row->fldShopWebsite != " " && $row->fldShopWebsite != null);
    $storeHasStudio = $row->fldSSStudio;
    $storeHasSnappyStudio = $row->fldStudio;
    $storeHasBusinessPrinting = $row->fldBusiness;
    $storeHasAnyStudio = $storeHasStudio || $storeHasSnappyStudio;
    $storeHasAnyExtras = $storeHasStudio || $storeHasSnappyStudio || $storeHasBusinessPrinting;

    $distance = $row->distance;

    if ($distance < 100) {

?>

<tr>
    <td>

<?php boxLightHeader(); ?>

    <div class="store-details-main-wraper">
        <a id="<?php echo($head); ?>" name="<?php echo($head); ?>" style="display:block;height:0px;width:0px;overflow:hidden;">$head</a>

        <span class="shopnametidy" style="display:none;"><?php echo($row->fldShopNameTidy); ?></span>

        <span class="shoplisttitle"><a href="/stores/<?php echo($row->fldShopNameTidy); ?>"><?php echo($row->fldShopName); ?></a></span>
        <span>
            <?php
                if ($row->distance) {
                    echo("($row->distance miles)<br />");
                }
            ?>
        </span>

        <?php if ($storeHasWebsite) { ?>
            <a href="http://<?php echo($row->fldShopWebsite); ?>" class="web-clickthru-tracking" target="_blank" rel="nofollow">
             <img src="/assets/images/icons/start-shopping-off.png" title="Start Shopping" class="img-swap" />Click &amp; Collect</a><br >
        <?php } ?>

        <div>
             <a href="/stores/<?php echo($row->fldShopNameTidy); ?>/map" class="map-tracking ">
                <img src="/assets/images/icons/map-32-off.png" title="map" class="img-swap" />Map 
            </a>

            <a href="/store-finder/direction/<?php echo($row->fldShopNameTidy); ?>" class="directions-tracking">
                <img src="/assets/images/icons/directions-32-off.png" title="directions" class="img-swap" />Directions
            </a>

            <span class="contactStore details-tracking">
            <img src="/assets/images/icons/store-contact-off.png" title="Contact" class="img-swap" />
            Contact details</span>

            <div class="contact-details-slider" style="height:140px;">
            <div class="contact-details" style="float:left;">
<?php
echo <<<END
<p>$fullAddress<br />Phone:
$row->fldShopTel<br />
$row->fldShopEmail</p>
<hr class="hor-bar-color" />
<p>Get these contact details by:

<span class="sendEmailNew sendLink details-email-tracking" style="font-weight:bold; font-size:1.2em; text-decoration:underline">email</span> or
<span class="sendTextNew sendLink details-text-tracking" style="font-weight:bold; font-size:1.2em; text-decoration:underline">text</span>
<input name="shopId" type="hidden" value="$row->fldID" />
<span class="shopId" style="display:none;">$row->fldID</span></p><hr class="hor-bar-color" />
END;
?>  
            </div>
            <div class="contact-form-placeholder" style="display:none;">foo</div>
            </div>
        </div>

        <div class="extra-services">
<?php
if ($storeHasAnyExtras) {
echo <<<END
<span class="contactStore details-tracking">Specialist services:</span> 
END;
}

if ($storeHasStudio){
echo <<<END
<img src="/assets/images/icons/portrait-studio.jpg" title="Snappy Snaps Studio" />
END;
}

if ($storeHasSnappyStudio){
echo <<<END
<a href="http://www.snappystudio.com/" target="_blank" rel="nofollow"> <img src="/assets/images/icons/snappy-studio-off.png" class="img-swap" title="Snappy Studio" /></a>
END;
}

if ($storeHasBusinessPrinting){
echo <<<END
<a href="http://www.snappysnapsprinting.co.uk/" target="_blank" rel="nofollow"><img src="/assets/images/icons/business-printing-off.png" class="img-swap" title="Business printing" alt="Snappy Snaps business printing" /></a>
END;
}
?>

    <span class="shoplistservice" style="visibility:hidden; font-size:2px;">
        <?php
            if ($storeHasAnyStudio){
                echo "Studio ";
            }
            if ($storeHasBusinessPrinting){
                echo "Business Printing";
            }
        ?>
    </span>

    <span class="shoplistaddress" style="visibility: hidden">
        <?php echo($addressTeaser); ?>
    </span>
    </div>
    </div>
<?php boxLightFooter(); ?>

    </td>
</tr>

<?php } ?>

<<<END之后可能有空格。 這是行不通的。 檢查該行末尾絕對沒有空格。

要么以某種方式添加了它,要么有可能在使用CRLF作為代碼換行符的環境(Windows?)和僅使用CR的計算機(Linux?)之間遷移。

echo <<<_END
//Woah, it works!
_END;

我認為您嘗試使用Heredoc構造。 PHP.net 這是正確的語法,嘗試一下

您的語法看起來不錯。 您可能想嘗試使用變量:

$html = <<<END
bla
bla
END;
echo $html;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM