0

我正在为 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 第 9 行

我该如何解决?

4

5 回答 5

1

你也需要有引号<div class="welcome_msg"></div>内引号。

像这样:

echo "<div class='welcome_msg'>Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br></div>";
于 2016-01-08T19:12:05.540 回答
0
echo '<div class="welcome_msg">"Welcome: '.ucwords($name).'. IP of our server is: '.ucwords($ip).' , and port is: '.ucwords($port).'<br></div>';

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

于 2016-01-08T19:12:38.623 回答
0

你也可以试试这个:

echo "<div class='welcome_msg'>Welcome: " . ucwords($name) . ". IP of our server is: " . ucwords($ip) . ", and port is: " . ucwords($port) . "<br></div>";
于 2016-01-08T19:13:33.153 回答
0
echo '<div class="welcome_msg"> Welcome: '.ucwords($name).'. IP of our server is: '.ucwords($ip).' , and port is: '.ucwords($port).'<br></div>';
于 2016-01-08T19:15:19.820 回答
0

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

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

echo "<div class=\"welcome_msg\">Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br></div>";
于 2016-01-08T19:15:52.030 回答