2015-12-28 70 views
0

好像我沒有真正想到交換機是如何工作的,導致它不可能(對我來說)正確。交換機中的佈局問題

我有這樣的代碼:

foreach ($this->timeofday as $key => $node) { 
    if (get_class($node) === 'DOMElement') { 
     if ($node->hasAttribute('class')) { 
      switch ($node->getAttribute('class')) { 
       case "cmil_salong": 
        echo '<h3>'.$node->nodeValue. '</h3>'; 
        break; 
       case "cmil_time": 
        echo $node->nodeValue .' '; 
        break; 
       case "mv_3d": 
        echo '<span class="label label-info">3D</span> '; 
        break; 
       case "cmil_rs": 
        echo '<span class="label label-info">Platser ' . $node->nodeValue . '</span> '; 
        break; 
       case "mv_txt": 
        echo '<span class="label label-info">Textad</span><br>'; 
        break; 
      } 
     } 
    } 
    if (get_class($node) === 'DOMAttr') { 
     if ($node->nodeName === 'href') { ?> 
       <a href="<?php echo $node->nodeValue ?>"><button type="button" class="btn btn-success btn-xs">book! <span class="glyphicon glyphicon-new-window"></span></button></a><br> 
      <?php 
     } 
    } 
} 

產生這樣的:

​​

How it looks

但這是預期的結果:

How i want it to look

最好

<div> 
    11:30 <span class="label label-info">3D</span> <span class="label label-info">textad</span> <span class="label label-info">platser 379</span> 
     <span class="label label-warning"> Du kan inte l&#228;ngre k&#246;pa biljetter till den h&#228;r f&#246;rest&#228s;llningen</span> 
</div> 

,或者取決於if ($node->nodeName === 'href')是真實的:

<div> 
    11:30 <span class="label label-info">3D</span> <span class="label label-info">textad</span> <span class="label label-info">platser 379</span> 
<button type="button" class="btn btn-success btn-xs">book! <span class="glyphicon glyphicon-new-window"></span></button> 
</div> 

我的問題:

  1. 我怎麼使它看起來像:第二圖像:http://i.stack.imgur.com/QyTTO.png

回答

0

試試這個:

foreach ($this->timeofday as $key => $node) { 
    $div = "<div>"; 
    if (get_class($node) === 'DOMElement') { 
     if ($node->hasAttribute('class')) { 
      switch ($node->getAttribute('class')) { 
       case "cmil_salong": 
        $div .= '<h3>'.$node->nodeValue. '</h3>'; 
        break; 
       case "cmil_time": 
        $div .= $node->nodeValue .' '; 
        break; 
       case "mv_3d": 
        $div .= '<span class="label label-info">3D</span> '; 
        break; 
       case "cmil_rs": 
        $div .= '<span class="label label-info">Platser ' . $node->nodeValue . '</span> '; 
        break; 
       case "mv_txt": 
        $div .= '<span class="label label-info">Textad</span><br>'; 
        break; 
      } 
     } 
    } 
    if (get_class($node) === 'DOMAttr') { 
     if ($node->nodeName === 'href') { 
      $div .= '<a href="'.$node->nodeValue.'"><button type="button" class="btn btn-success btn-xs">book! <span class="glyphicon glyphicon-new-window"></span></button></a><br>'; 
     } 
    } 
    echo $div .'</div>'; 
} 
+0

謝謝!但我仍然沒有得到預期的結果 – Adam