使用CSS样式表格式化PHP值

I'm trying to format a PHP value from my script with a CSS style so it look the same then my html text preceding it. Here is my code:

<p>Your surname is: </p><?php echo "<div id='php'>" $surname; "</div>" ?>

what i'd like to get is

Your name is Remi

all formatted the same way, what I get now is just an error and my PHP page does not show at all.

You have to use . (a dot) to concatenate your strings:

<p>Your surname is: <?php echo "<span id='php'>" .  $surname . "</span>"; ?></p>

edit: you should use a span tag, not a div, to enhance your php output.

Your error is that you have a space between your string literal and your variable.

There is no need to echo the div tags from PHP, so don't.

You also shouldn't echo out raw text into the page, convert it to HTML first.

<p>Your surname is: </p>
<div id='php'><?php echo htmlspecialchars($surname); ?></div>
<p>Your surname is: <span id="php"><?php echo $surname; ?></span></p>

You could also go for the shorter notation:

<p>Your surname is: </p>
<div id='php'><?= $surname ?></div>

The semi-colon ends the statement. So PHP thinks that "</div>" after the semicolon is another PHP command. That causes an error and prevents the page from appearing. Move the semicolon so it's just before the ?>, and it should work.

Someone correct me if I'm wrong: Using a might cause some layout issues. I don't believe that "Your surname is" and the $surname value will appear on the same line.