0

I have 35.php that includes common menu for my website. 36.php page should display the menu by using include() Why doesn't this work?

My error:enter image description here

35.php is shown below;

<?php
   echo "<a href="index.htm">Home</a>
   <a href="aboutphp.html">PHP</a> 
   <a href="abouthtml.html">HTML</a>
   <a href="aboutcss.html">CSS</a> <br />";
?>

36.php is shown below;

enter code here
  <html>
  <body>
      <?php include("35.php"); ?>
      <p>About Menu is imported from 35.php file</p>
  </body>
  </html>
Kasuni
  • 83
  • 8

1 Answers1

1

You missused the ". They include the string but you also used them for the href. But that closes the string

 echo "<a href="

This is where the String ends for PHP and it wants either a ; fo finish the statement or a . to connect it to another string.

So this is what you could to to solve it:

echo '<a href="index.htm">Home</a>
<a href="aboutphp.html">PHP</a> 
<a href="abouthtml.html">HTML</a>
<a href="aboutcss.html">CSS</a> <br />';

With switching the "to a ' The string symbol is now the ' and therefor the " can be used int he string normaly.

Otherwise you could also escape the " like this \" inside the string:

    echo "<a href=\"index.htm\">Home</a> ...
DocRattie
  • 1,392
  • 2
  • 13
  • 27
  • Sir, thank you for the advice. I have another question. What happens if I remove all php syntax from 35.php file and just keep remain markup only? Is it mandatory to echo markup using PHP like I have done? – Kasuni Mar 17 '16 at 16:05
  • 1
    @Kasuni There is no need to use PHP at all. You could just do all of that in HTML, or if you still need PHP for somethin else mix PHP and HTML with `` to open and close the PHP parts. – DocRattie Mar 17 '16 at 16:21
  • Ohh! Thank you so much. Now I understand completely. Thank you so much. I also tried to include it works!! Is it legal or good practice to include a html file also? – Kasuni Mar 17 '16 at 16:31
  • 1
    It's good practice to have a well structured code. If that includes including .html files that's fine. – DocRattie Mar 17 '16 at 16:48