0

I am developing some code for my School Website and I have a long php file. I need to echo html and in that I need to include php like so.

  echo '<p>. $url . </p>';

This seems to be working small amounts of Html Code but does not work with a lot of html code. Can someone please help me?

Navvye
  • 31
  • 5
  • 1
    Please define "a lot" and "does not work". What exactly is the limit you have found, and what exactly happens when you exceed it? – ADyson Jun 29 '20 at 18:44
  • Single quotes will not process variables inside, and this is not how you concatenate strings. – aynber Jun 29 '20 at 18:44
  • A lot as in 317 lines of code. Should I post it? By Does not work I mean it shows blank. – Navvye Jun 29 '20 at 18:45
  • @aynber Can you please demonstrate? – Navvye Jun 29 '20 at 18:45
  • 1
    A little bit of basics helps you a long way: https://www.php.net/manual/en/language.operators.string.php – Markus AO Jun 29 '20 at 18:46
  • See https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – aynber Jun 29 '20 at 18:47
  • 1
    Something to consider if you start to want to separate the PHP and HTML (sort of) would to be look at some template engines -https://stackoverflow.com/questions/197466/whats-a-good-templating-system-for-php – Nigel Ren Jun 29 '20 at 18:51
  • Can you show the opening PHP tag? In your [comment](https://stackoverflow.com/questions/62644708/trouble-with-php-inside-html-inside-php-extended-version#comment-110782813) below, it appears that you're using `short_tags` which is discouraged but also disabled on some setups. I think it may even be removed in PHP 7+. This could account for why you're not seeing anything on screen. It's possible the PHP isn't even processing... – War10ck Jun 29 '20 at 18:52

2 Answers2

0

Try like that !

 echo '<p>'.$url.'</p>'; 

you must enclose text before and after a variable 'text'.$var.'text'; and thats goes for concatenate variables on variables to

denn0n
  • 155
  • 1
  • 12
0

Inside the single quotes php variables treats as a text not like variables, so if you want to use your php variable with html tags you can either enclosed it with double quotes like below

  echo "<p> $url </p>";

Or you can concatenate php variable with strings or html tags

//with single quotes
echo '<p>'. $url . '</p>';
//With double quotes
echo "<p>". $url . "</p>";

May this will help you.
Happy Coding!

Badrinath
  • 501
  • 5
  • 14