-1

There is a tag:

<br />

Ok, but why double quotes and dot before first quote are needed with br in php, when in HTML there is only <br />? :)

For example:

echo $variable1."<br />";
echo $variable2;
albert
  • 8,285
  • 3
  • 19
  • 32
Karlsson
  • 15
  • 3
  • Because one is PHP and one is HTML. They aren't the same thing. The period is to add the string `
    ` to the variable1 that you're echoing.
    – aynber Dec 28 '20 at 17:35
  • https://www.php.net/manual/en/language.operators.string.php – M. Eriksson Dec 28 '20 at 17:37
  • Ah, ok, it is understandable, although in use it seems breakneck at first glance :) Is there any other (simpler) alternative operator/expression/tag that would do the same thing? – Karlsson Dec 28 '20 at 17:40
  • Does this answer your question? [Reference — What does this symbol mean in PHP?](https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – tyleha Dec 28 '20 at 18:07
  • No ;( I am looking for something to add a new line in php instead of treating this break between lines as a string. I tried to use \n, but it doesnt work. – Karlsson Dec 28 '20 at 18:12

2 Answers2

0

That's an echo statement with a concatenated string. You can use just a regular old <br>, but you have to put it as HTML outside of the PHP tags (<?php ?>).

These are all valid in a PHP file:

<?php ?> 
<br>
<!--This one is specifically to show that a regular br has to be 
outside of the php tags.-->
<?php
echo "<br>";
?>
<?php
echo $var."<br>";
?>
Liftoff
  • 24,717
  • 13
  • 66
  • 119
0

Double Quote

  1. Double quote strings will display a host of escaped characters (including some regexes), and variables in the strings will be evaluated. An important point here is that you can use curly braces to isolate the name of the variable you want evaluated. For example let's say you have the variable $type and you want to echo "The $types are". That will look for the variable $types. To get around this use echo "The {$type}s are" You can put the left brace before or after the dollar sign. Take a look at string parsing to see how to use array variables and such.

Dot

  1. Two string operators are available. The first is the concatenation operator ('.') that returns its right and left argument concatenation. Second is the concatenation operator of assignment ('.='), which adds the right-hand argument to the left-hand argument. For further details, please read Assignment Operators.
Sam
  • 11
  • 1
  • 1
  • 5