2012-07-10 146 views
0

我已經投入了2天的工作,試圖解決這個問題,當我在我的本地機器上加載下面的代碼相當一部分它的工作原理,當我把它做真正的網站上,雲它會提示這個錯誤。解析錯誤:語法錯誤,意外'<'-----使用echo <<< END ** END; -------

Parse error: syntax error, unexpected '<' 

這種情況發生,當它到達行74

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

目前我的網站被打破任何幫助將apreciated。

代碼:

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

這段代碼[似乎是工作](http://codepad.org/ZaboSRsT)。你確定錯誤在那條線上嗎? – jprofitt 2012-07-10 14:26:16

+0

嗯......我現在沒有時間檢查,但您確定END不是保留字嗎?此外,當涉及到空白時,Heredocs可能會很痛苦 - 我會檢查以確保在終止令牌之前/之後沒有任何額外的空白。 – 2012-07-10 14:26:40

回答

1

<<<END之後可能有空格。這不起作用。檢查該行末尾是否有空格。

無論它被以某種方式加入,或者CRLF在代碼中使用的換行符(的Windows?)到只使用CR(Linux呢?)

+0

對,任何添加的字符都會影響解析。 – 2012-07-10 14:33:12

+0

謝謝你會檢查.... – user1514899 2012-07-10 16:37:10

+0

我檢查了白色的空間,他們是正確的, – user1514899 2012-07-10 16:39:15

0

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

我認爲你試圖用定界符建設。 PHP.net。 這裏是正確的語法,試試吧

+3

@ametren - (張貼反對軍閥的答案,因爲你現在已經刪除)我downvaoted您的文章,但我還沒來得及寫我的評論解釋爲何要刪除......但建議你在定界符讀了 - HTTP:/ /uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc – 2012-07-10 14:27:51

+0

@MarkBaker謝謝你的提示,它不是我遇到過的。它達到-4沒有評論,所以我刪除了它,但我感謝你糾正我的知識的努力! – ametren 2012-07-10 14:38:19

+0

謝謝我會研究一下,很高興看到解決方案。 – user1514899 2012-07-10 16:16:03

0

你的語法看起來機器很可能是因爲您的環境之間移動精細。你可能想嘗試使用一個變量:

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

OH還有另一種選擇,非常感謝,我今天剛加入,我收到了很好的答覆,感謝來自倫敦的各位... – user1514899 2012-07-10 16:16:56

相關問題