交换机布局问题

时间:2015-12-28 11:39:37

标签: php css

好像我还没弄清楚开关是如何工作的,因为不可能(对我来说)做对了。

我有这段代码:

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

这产生了这个:

<h3>FS 4</h3>10:50 
<span class="label label-info">Platser 74</span> 
<span class="label label-info">3D</span> 
<span class="label label-info">Textad</span><br>
<button type="button" class="btn btn-success btn-xs">book! <span class="glyphicon glyphicon-new-window"></span></button>

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

1 个答案:

答案 0 :(得分: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>';
}