-3
<?php
   if(something==something){
      for($i=0;$i<sizeof($array);$i++){
 ?>
<table>
   <tr>
      <th><?php echo date("m d y");?></th>
   </tr>
</table>
    <?php
   }
  }
?>

If I would use sintax like thiks would the code work? I couldn't find any discussion on this, and I am new to php so every advice would be helpful and appreciated. Thanks!

terza
  • 46
  • 9
  • 3
    Why don't you just try and see? ;-) A couple of remarks: `date(m d y)` needs to be quoted, like `date("m d y")`. And `for (int..)` should just be `for ($i...` - could also use a `foreach` loop, look it up in the manual. – Qirel May 27 '17 at 08:42
  • I am getting some problems with the code I'm using but I think the problem is not in the code, but in the server.. I am politely asking if someone has some experience with the sintax like this so I can get some advice. – terza May 27 '17 at 08:44
  • Use the manual http://www.php.net - and enable error-reporting, `error_reporting(E_ALL); ini_set("display_errors", 1)` at the top of your file, after ` – Qirel May 27 '17 at 08:45
  • I know.. I was just typing quick not paying attention to that things.. It doesn't matter what the code is,I am asking about the syntax – terza May 27 '17 at 08:45
  • What part of the code are you referring to when you say "syntax"? If you can exit PHP to output HTML? Then yes, you can. – Qirel May 27 '17 at 08:47
  • Thanks for sharing this with me. Helped me a lot. I couldn't find that discussion. – terza May 27 '17 at 08:53

3 Answers3

1

Yes, you can.

1) Actually you can use php within html.

Eg : - <h1><?php echo "hello world"; ?> .

2) You can't use html within php. But exception if you use echo with html

Eg :- <?php echo "<h1>Hello world</h1>"; ?>

varman
  • 8,704
  • 5
  • 19
  • 53
1

You can use HTML inside you PHP code.

<?php
    if(something==something){
    for($i=0;$i<sizeof($array);$i++){
        echo '<table>
              <tr>
              <th>'.date("Y-m-d").'</th>
              </tr>
          </table>';
    }
    }
?>
Gautam D
  • 330
  • 3
  • 15
0

No, but you can do this:

<?php if(something==something){ 
     for($i=0;$i<sizeof(array);$i++){
         echo "<table><tr><th>";
         echo date("m d y");
         echo "</th> </tr> </table>";
      }
 } ?>
Qirel
  • 25,449
  • 7
  • 45
  • 62
knurzl
  • 358
  • 3
  • 10