在回声中执行回声

时间:2017-05-02 21:03:35

标签: php switch-statement echo

我有这段代码:

 echo '<div style="background-size: 100%; background-repeat: no-repeat; 
 background-image:url(http://render-api-eu.worldofwarcraft.com/static-
 render/eu/' . $newString.');">

 switch ($rasse) {
case "11":
    echo "Tauren";
    break;
case "12":
    echo "Troll!";
    break;
default:
    echo "No Character.";
}

问题是我在回声内部回声,所以“switch-statement”没有被执行。我该如何处理?

1 个答案:

答案 0 :(得分:1)

您忘记在';之后编写echo '<div style="background-size: 100%;...,这会导致问题(以及代码未按预期运行的原因):

echo '<div style="background-size: 100%; background-repeat: no-repeat;  
                  background-image:url(http://render-api-eu.worldofwarcraft.com/static-render/eu/' . $newString.');">';
switch ($rasse) {
    case "11":
        echo "Tauren";
    break;
    case "12":
        echo "Troll!";
    break;
    default:
        echo "No Character.";
}