gpt4 book ai didi

php - switch布局问题

转载 作者:行者123 更新时间:2023-11-28 06:38:22 24 4
gpt4 key购买 nike

似乎我还没有真正弄清楚开关是如何工作的,因为(对我来说)不可能把它弄对。

我有这个代码:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com