0

I'm working on a website for TeamsSpeak server and I want to style a text that is displayed using php:

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

I want to style the whole text. I tried adding tags, for example

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

It shows an error: Parse error: syntax error, unexpected '/' in C:\xampp\htdocs\index.php on line 9

How can I fix it?

5 Answers5

1

You need to have the <div class="welcome_msg"> and the </div> within quotes too.

Like this:

echo "<div class='welcome_msg'>Welcome: ".ucwords($name).". IP of our server is: ".ucwords($ip)." , and port is: ".ucwords($port)."<br></div>";
andi
  • 6,442
  • 1
  • 18
  • 43
0
echo '<div class="welcome_msg">"Welcome: '.ucwords($name).'. IP of our server is: '.ucwords($ip).' , and port is: '.ucwords($port).'<br></div>';

** numeric words (IP and Port) didn't need to ucwords

Saeed M.
  • 2,216
  • 4
  • 23
  • 47
0

You can also try with this one:

echo "<div class='welcome_msg'>Welcome: " . ucwords($name) . ". IP of our server is: " . ucwords($ip) . ", and port is: " . ucwords($port) . "<br></div>";
Jonathan Zúñiga
  • 645
  • 3
  • 13
  • 25
0
echo '<div class="welcome_msg"> Welcome: '.ucwords($name).'. IP of our server is: '.ucwords($ip).' , and port is: '.ucwords($port).'<br></div>';
Santosh Patel
  • 549
  • 2
  • 13
0

Your HTML tags shout be treated as text and wrapped in quotes wit your other text.

Because your HTML includes quotes inside the text you need to escape the quotes inside your text by adding a \ before them. Escaping your quotes tells PHP not to treat that specific quote as a closing quote for the string.

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