解析错误:语法错误,意外'<' -----使用echo<<

时间:2012-07-10 14:18:52

标签: php syntax

我已经投入了大量的2天工作来尝试解决这个问题,当我在我的本地计算机上加载以下代码时,当我在云端的真实站点上执行此操作时,它会提示此错误。< / p>

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 } ?>

3 个答案:

答案 0 :(得分:1)

<<<END之后你可能有空格。这不行。检查该行末尾是否完全没有空格。

要么以某种方式添加它,要么你可以在CRLF用作代码换行符(Windows?)到只使用CR的机器的环境之间移动(Linux ?)

答案 1 :(得分:0)

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

我认为您尝试使用 heredoc 构造。 PHP.net。 这是正确的语法,试试吧

答案 2 :(得分:0)

你的语法看起来很好。您可能想尝试使用变量:

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