0

Can anyone tell here, what is the command to run html with php script. Normally in my linux terminal, if i want to run html, my command is

firefox <filename>.html

It works fine and display output in firefox browser. But some how, when I add php script, the browser doesn't show the output from php script. It show source code. I try the answer from the forum below, it doesn't work for me.

Using .htaccess to make all .html pages to run as .php files?

How to run a php script inside a html file?

So here, i want to ask 1) What is the step to run html with php script

2) what is the command to run?

3) The source code, need to save in .html or .php ?

Is there any way to run php in browser without using apache?

daffodil
  • 197
  • 1
  • 9
  • 2
    I don't understand the question. PHP scripts combined with HTML can be run directly in browsers – symlink Jul 07 '19 at 03:39
  • I'm not sure about PHP, but you can try an NPM package called ['live-server'](https://www.npmjs.com/package/live-server) it's easier to run a static html in a webserver – kubido Jul 07 '19 at 03:54
  • Well to run local Php scripts from a browser, you need a web server that processes the Php script and forwards the result to the browser. The Php script must be served by a web server. It cannot be processed directly by a browser – Nadir Latif Jul 07 '19 at 04:12
  • This works on this win10 box (which has a copy of xampp installed and has a copy of the specified script) "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" localhost/snippets/pdfInfo.php – enhzflep Jul 07 '19 at 04:42

2 Answers2

2

Rename file.html to file.php and check. I think you write PHP and HTML in a single document, and you use only html extension.

sajad abbasi
  • 1,988
  • 2
  • 22
  • 43
2

You can't run php codes without install PHP package on your OS. your browser can't understand your php code without this package, So your browser show source code. After that you can run php file as a page or put it into a html page by iframe html tag.

Abbas.Kh
  • 37
  • 6
  • can you explain more on this? – daffodil Jul 07 '19 at 07:25
  • php syntax code only can run with php module that you should install on your server or OS. for example you can install xampp software on to Windows OS, then you can run php codes on your system. PHP codes can compile on server side only, So you can't open php file as html file on browser without install php package. – Abbas.Kh Jul 14 '19 at 05:21