2012-09-16 44 views
1

去掉空格的,我有這個循環得到在定界符

foreach ($unserialized as $key => $value) { 
$foo = <<<EOT 
<div class='krudItem' id='xxx'><form class='aj' name='itemForm' method='post' 
action=''><section><label>Slider Title</label><input type='hidden' 
name='sliderKey' value=$key/><input type='text' name='sliderTitle' value='$value 
['slidertitle']'/></section><section> <label>Slider Location</label> 
<input type='text' 
name=$value['sliderlocation']value='ipsum'/></section><section><label>Slider 
Description</label><textarea name='sliderDescription'>$value 
['sliderdescription']</textarea></section><button name='saveNew' class='saveNew' 
value='save'>save</button><button name='newCancel' value='cancel' 
class='deleteNew'>cancel</button></form></div> 
EOT; 
echo $foo; 

,但每次我運行它,我得到

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),

我一直在讀什麼PHP說,大約http://us2.php.net/tokens和我都想盡其他可能的解決方案,但錯誤仍然存​​在。有一些白色空間,但我不知道我將如何處理好他們。

回答

2

你需要將你的變量包含在括號中。

這應該爲你工作:

<?php 
foreach ($unserialized as $key => $value) { 
    $foo = <<<EOT 
    <div class='krudItem' id='xxx'> 
     <form class='aj' name='itemForm' method='post' action=''> 
      <section> 
       <label>Slider Title</label> 
       <input type='hidden' name='sliderKey' value={$key}/> 
       <input type='text' name='sliderTitle' value='{$value['slidertitle']}'/> 
      </section> 
      <section> 
       <label>Slider Location</label> 
       <input type='text' name={$value['sliderlocation']} value='ipsum'/> 
      </section> 
      <section> 
       <label>Slider Description</label> 
       <textarea name='sliderDescription'> 
        {$value['sliderdescription']} 
       </textarea> 
      </section> 
      <button name='saveNew' class='saveNew' value='save'>save</button> 
      <button name='newCancel' value='cancel' class='deleteNew'>cancel</button> 
     </form> 
    </div> 
EOT; 
    echo $foo; 
} 
+0

真的嗎?您已將所有HTML屬性名稱更改爲變量插值,您確定嗎? – lanzz

+0

崇高的插件,它做到了:S –