1

基本上只是想知道是否可以使用 if 语句class向我的div哪个我添加一个。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>";
}

如您所见,我确实尝试了几种方法,但没有成功。

4

2 回答 2

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>";
        }
于 2017-06-15T14:04:56.840 回答
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>";
}
于 2017-06-19T16:06:15.110 回答