-1

hi i've aproblem with using php with html while i'm trying to execute php code at linux command line

#php code.php

it run properly but if i write the php code into html as

<html>
<body>
//php code
</body>
</html>  

then run in browser the php code appear as text not executed

  • Is the html page with php extension? – Lelio Faieta Feb 05 '18 at 07:41
  • Did you configure your web server to serve php pages? – Lelio Faieta Feb 05 '18 at 07:42
  • in this case the file with html extension localhost/code.html when i've tried to browse localhost/code.php it appear nothing clear page ---- i didn't change apache configuration i just installed php for linux then started apache service and tried the code.html which contain php and then the code appear as text – Hamdy A. Hamdy Feb 05 '18 at 08:48
  • First Apache needs to be configured with php. Google for this. Second File extension needs to be php to be parsed by php before being issued to the browser. Then enable error reporting to see the issues in your php code. – Lelio Faieta Feb 05 '18 at 08:54
  • ok first i've checked that apache2 configured to serve php second in web design i need to use html & css with php so the index file should be in html .. the problem clearly that php doesn't work with & – Hamdy A. Hamdy Feb 05 '18 at 09:19
  • A page with php extension is an html page that is pre-parsed by php and served as html to the browser – Lelio Faieta Feb 05 '18 at 09:29

1 Answers1

0

You should write code in php tag i.e. <?php ?>

<html>
<body>
  <?php  //php code here  ?>
</body>
</html>  

You can follow the PHP Syntax

Aftab H.
  • 1,517
  • 4
  • 13
  • 25