php - switch布局问题

标签 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 ($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

最佳答案

试试这个:

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

关于php - switch布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34492844/

相关文章:

php - 在 PHP 中使用可变变量是不好的做法吗?

javascript - 传单 map 已移出 div 标签

css - 使用 CSS : Why this code won´t work? 根据复选框显示/隐藏内容

php - 用对应的口音替换口音

php - 使用 laravel eloquent 将左连接中的 null 值替换为 N/A

php - Mysql PHP查询更新

javascript - 循环 Ajax 调用

html - 如何使元素宽度为 : 100% minus padding?

jquery - 如何使用 html5 css 和 jquery 创建这个特殊的加载器?

html - 每当 div 标签之间有 http ://www. .. 时自动激活