0

I'm a beginner. I'm trying to run this code in a w3 tutorial. but it's producing an error. what am I doing wrong? thanks

,,,

   <?php
    echo "<h1>PHP is Fun!</h1>";
    echo "

    <table style="border: 1px solid black;">
          <tr>
                <th>
                        <h2> Hello world! </h2>
                </th>
          </tr>
    </table>

    <br> ";

?> 

,,,

  • What is the error you are getting? – Wais Kamal Jun 08 '20 at 09:24
  • PHP Parse error: syntax error, unexpected 'border' (T_STRING), expecting ',' or ';' in /home/EhVNMZ/prog.php on line 9 (I didn't include the html and body tags in my example so the line number may not be correct) – Ben Lowrey Jun 08 '20 at 09:26
  • You've got double quotes inside a string using double quotes as an enclosure. I'd find a better tutorial, to be honest :-O – Ben Hillier Jun 08 '20 at 09:27

1 Answers1

0

Your quotes conflict with each other. If you use double quotes in your string, you should either use single quotes as the delimiters, or use double quotes but escape all other double quotes in your string. So, this should work:

<?php
  echo "<h1>PHP is Fun!</h1>";
  echo '
    <table style="border: 1px solid black;">
      <tr>
        <th>
          <h2> Hello world! </h2>
        </th>
      </tr>
    </table>
    <br>';
?> 
Wais Kamal
  • 4,312
  • 2
  • 11
  • 26