Joseph Joseph - 1 year ago 82
HTML Question

PHP implementation into HTML

I'm currently beginning with PHP and I wanted to get started with a mini-project for some hands-on experience. Here's the code that I began with:

<h3>Some example title</h3>
$randomNumber = rand(1000,9000);
print "Here's a random number: {$randomNumber}.";
<p>Some more text.</p>

However, when I saved it as index.php and previewed it on Google Chrome, the PHP part doesn't show up. Can anyone help me realize what I'm doing wrong?


Answer Source

To run PHP code (server side) you need a server, or a 'server-emulator' some of the most commonly used are:

Unlike the html in your .php files, the php code must be processed by a server and returned to the browser. I've tested your code with a server and it works like a charm.

After installing one of the above "emulators" you need to (this is a simplified tutorial, check a real tutorial):

  1. place your .php files in the public_html or htdocs folders that are created in the emulator's folder in your computer.
  2. Turn on your server
  3. go to localhost/your-file-path/index.php

If you only need to test soft code (like what's on yout example) and not develop whole projects use IDONE

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download