Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PHP script to run in browser? [duplicate]

Tags:

php

Possible Duplicate:
PHP script not running on browser

I'm trying to work with PHP and am very new at it. I'm trying to just test the waters with a simple hello world program. I've tried it like this:

<html>
<body>

<h>Php File</h>

<?php echo "hello world";?>

<p>Did it work?</p>

</body>
</html>

and then opening the html file in my browser (currently chrome). Only the did it work? part shows in the browser. Not the actual PHP stuff I'm trying to run. Any ideas?

I also tried it with

<html>
<body>

<h>Php File</h>

<form action="helloworld.php" method="post"></form>

<p>Did it work?</p>

</body>
</html>

As an HTML file, and then running the following PHP script in a file called helloworld.php

<html>
<body>

<?php
echo "hello world";
?>

</body>
</html>  

I cannot figure out why neither is working. Please help me get past this easy part so I can get to the hard stuff!

like image 709
user1459268 Avatar asked Jun 21 '12 18:06

user1459268


People also ask

Why PHP script is not running in browser?

PHP is not intended for execution in a browser. It is for web servers to execute, or other preprocessing on the PHP-installed computer. PHP runs in several incarnations when installed on a computer: from the command line.

How do I copy a PHP source code from a website?

Chrome: Right-click a blank space on the page and choose View Page Source. Highlight the code, then copy and paste to a text file. Firefox: From the menu bar, choose Tools > Web Developer > Page Source. Highlight the code, then copy and paste to a text file.

How do I open a PHP file in my browser?

You can open current file in browser using following methods: Click the button Open In Browser on StatusBar. In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser. Use keybindings Shift + F6 to open more faster (can be changed in menu File -> Preferences -> Keyboard Shortcuts )

Does PHP run in browser?

PHP Is Not Part of Your Browser. And here's where things change from the easy, browser-centric view of the world. When you download a web browser, you get HTML, CSS, and JavaScript, but you do not get PHP. PHP scripts—which you'll soon be writing—have to be interpreted by the PHP interpreter program, called php.


2 Answers

You can't just open the file in your web browser. You need to run it in a web server. Depending on your platform there is

  • WAMP
  • MAMP
  • XAMPP
like image 73
John Conde Avatar answered Oct 10 '22 23:10

John Conde


PHP is not intended for execution in a browser. It is for web servers to execute, or other preprocessing on the PHP-installed computer.


PHP runs in several incarnations when installed on a computer:

  • from the command line
  • from a web server
  • spawned internally by an IDE or GUI frontend for PHP

The web server use is common. A browser asks a web server to retrieve somepage.html. A webserver (like Apache, IIS, etc.) retrieves somepage.html and preprocesses it. If a PHP tag is detected, it calls the installed PHP system to parse the PHP tag. Any result is substituted into the web page being rendered. The web server repeats this process for all tags needing preprocessing, then delivers the rendered page over the network wire to the browser.

like image 40
wallyk Avatar answered Oct 10 '22 22:10

wallyk