0

This is my first time using php. I am having a little trouble starting out simple such as just printing "hello world" through php inside an html document. I have an html document with various elements in it and when I print

  <?php echo "hello world" ?>

The html document won't accept the php tags. I have read that html docs won't accept php tags, if this is true how do I integrate php and html? If I just use a php file aptana won't allow me to preview the document.

David Jarrin
  • 1,635
  • 4
  • 19
  • 40

1 Answers1

1

Change the file extension from HTML to PHP. View it in the browser instead of inside Aptana. Also add a semi-colon to the end of the string.

<?php echo "Hello World"; ?>

It sounds like you need to read a really basic tutorial on setting up a webserver locally by the way.

XAMPP is pretty popular so take a look at this guide: https://www.udemy.com/blog/xampp-tutorial/

Nathan Dawson
  • 18,138
  • 3
  • 52
  • 58
  • sounds about right. the biggest thing being the `.html` to `.php` – Phil Feb 20 '14 at 01:37
  • The semi-colon isn't required for a one-liner as such, although it is good practice to do so (and just as long as it's the last line). Plus, the `?>` is also something that doesn't need to be there, unless HTML is placed underneath PHP. Another thing is that `.html` can be treated to run as PHP. – Funk Forty Niner Feb 20 '14 at 01:40
  • While they're on hello world I don't think they need to know how to run .html as PHP :P – Nathan Dawson Feb 20 '14 at 01:43
  • Thanks, I actually am using XAMPP. Is the preview function in aptana just broken? So I guess when ever I have a page that includes any type of php I just should save as php (which I'm guessing will also accept html tags). – David Jarrin Feb 20 '14 at 01:53
  • The preview function you see in a lot of IDEs is for plain old HTML. PHP needs to be processed so you can only view it in a browser. This isn't a bug in your IDE. – Nathan Dawson Feb 20 '14 at 09:54