【问题标题】:Style php text which uses variables using css [duplicate]使用css使用变量的样式php文本[重复]
【发布时间】:2016-04-13 13:32:33
【问题描述】:

我正在开发 TeamsSpeak 服务器的网站,我想为使用 php 显示的文本设置样式:

echo "Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br>";

我想为整个文本设置样式。我尝试添加标签,例如

echo <div class="welcome_msg">"Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br>"</div>;

它显示一个错误:Parse error: syntax error, unexpected '/' in C:\xampp\htdocs\index.php on line 9

我该如何解决?

【问题讨论】:

    标签: php html css styles text-styling


    【解决方案1】:

    您还需要在引号内加上&lt;div class="welcome_msg"&gt;&lt;/div&gt;

    像这样:

    echo "<div class='welcome_msg'>Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br></div>";
    

    【讨论】:

    • 谢谢,现在可以使用了!
    【解决方案2】:
    echo '<div class="welcome_msg">"Welcome: '.ucwords($name).'. IP of our server is: '.ucwords($ip).' , and port is: '.ucwords($port).'<br></div>';
    

    ** 数字字(IP 和端口)不需要ucwords

    【讨论】:

      【解决方案3】:

      你也可以试试这个:

      echo "<div class='welcome_msg'>Welcome: " . ucwords($name) . ". IP of our server is: " . ucwords($ip) . ", and port is: " . ucwords($port) . "<br></div>";
      

      【讨论】:

        【解决方案4】:
        echo '<div class="welcome_msg"> Welcome: '.ucwords($name).'. IP of our server is: '.ucwords($ip).' , and port is: '.ucwords($port).'<br></div>';
        

        【讨论】:

          【解决方案5】:

          您的 HTML 标记会被视为文本,并用引号括起您的其他文本。

          因为您的 HTML 在文本中包含引号,您需要通过在它们之前添加 \ 来转义文本中的引号。转义引号告诉 PHP 不要将该特定引号视为字符串的结束引号。

          echo "<div class=\"welcome_msg\">Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br></div>";
          

          【讨论】:

            猜你喜欢
            • 2013-09-12
            • 1970-01-01
            • 2011-07-04
            • 2020-07-20
            • 2020-07-09
            • 2013-08-02
            • 2020-08-22
            • 1970-01-01
            • 2018-06-16
            相关资源
            最近更新 更多