使用php echo的div中的类

时间:2017-06-15 13:57:44

标签: php if-statement echo request-uri

基本上想知道是否可以使用if语句向classdiv添加echo

我的代码:

$currentpage = $_SERVER['REQUEST_URI'];

if ($currentpage == "/room/penthouse-suite/"){
echo "<div class="' .text-center text-emphasis text-lg. '">test 
penthouse</div>";
}
elseif ($currentpage == "/room/garden-room/"){
echo "<div class="text-center text-emphasis text-lg">test garden</div>";
}
elseif ($currentpage == "/room/ocean-suite/"){
echo "<div class='text-center text-emphasis text-lg'>test ocean</div>";
}
elseif ($currentpage == "/room/mountain-suite/"){
echo "<div class='text-center text-emphasis text-lg'>test mountain</div>";
}

正如你所看到的,我确实尝试了几种方法,但没有让它发挥作用。

2 个答案:

答案 0 :(得分:0)

双引号不应在双引号内使用,单引号内不应使用单引号。我解决了这个替换引号。请试试这个

if ($currentpage == "/room/penthouse-suite/") {
            echo '<div class="text-center text-emphasis text-lg">test 
penthouse</div>';
        } elseif ($currentpage == "/room/garden-room/") {
            echo '<div class="text-center text-emphasis text-lg">test garden</div>';
        } elseif ($currentpage == "/room/ocean-suite/") {
            echo "<div class='text-center text-emphasis text-lg'>test ocean</div>";
        } elseif ($currentpage == "/room/mountain-suite/") {
            echo "<div class='text-center text-emphasis text-lg'>test mountain</div>";
        }

答案 1 :(得分:0)

已解决

基本上只在双引号旁边使用单引号。(简单)

if ($currentpage == "/room/penthouse-suite/"){
echo "<div class='text-center text-emphasis text-lg'>test 
penthouse</div>";
}
elseif ($currentpage == "/room/garden-room/"){
echo "<div class='text-center text-emphasis text-lg'>test garden</div>";
}
elseif ($currentpage == "/room/ocean-suite/"){
echo "<div class='text-center text-emphasis text-lg'>test ocean</div>";
}
elseif ($currentpage == "/room/mountain-suite/"){
echo "<div class='text-center text-emphasis text-lg'>test mountain</div>";
}