This question has already been answered:

How to insert a variable between p tags

 $message = ' <html> <head> <title></title> </head> <body> <p>Например тут</p> </body> </html>'; 

Reported as a duplicate by members of Visman , mymedia , Darth , br3t , Cheg 11 Aug '17 at 20:07 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Например тут on '.$xyz.' - Visman
  • one
    You can also replace single quotes with double quotes and stupidly insert a variable in the right place of the line - Dmitriy Simushev
  • Or on {$var} - DaemonHK
  • Do not do this. Posted in reply. - Alexander Bragin

2 answers 2

PHP executes code inside delimiters, such as <?php ?> . All that is outside the limiters, is displayed without changes. This is mainly used to insert PHP code into an HTML document ...

Proper use of PHP in context with HTML markup

 <html> <head> <title><?php echo $title; ?></title> </head> <body> <p><?php echo $myVar; ?></p> </body> </html> 

That's right, and it will be more convenient for you in the future if you organize the structure of your project as follows: insert the script into the HTML markup, and not PHP output the markup (unless of course it is generated from something).

These are the basics of syntax.

If you later want to use any template engine, it will also be easier for you.

Additional Information

  • Look at the output of the first variable. - Visman
  • @Visman thanks, corrected. - Alexander Bragin

Still there is such an option, more concise, in my opinion

 <html> <head> <title><?=$title?></title> </head> <body> <p><?=$myVar?></p> </body> </html> 
  • And how can a person display information to the user using your answer? - Visman
  • Try it yourself. Announce in the script php, which is connected, for example, before the html code in which the specified variables are located, and below this part of the code. But again, this entry is specifically for the example that you indicated, where the output structure of the form is used: <tag> <? Php echo $ a; ?> </ tag>. The option that I pointed out is a short entry <? Php echo "something"?> - kstkt