Home » Tutorials » PHP » Introduction

Introduction

First off remember that PHP pages are not limited to purely writing PHP code. The PHP code is only inside of the <?php and ?> tags. Anything outside of those tags would not be PHP and could be anything that you could normally write in an HTML file. With a standard PHP file that is not going to be used as an include, you will have html tags in the file.

I am sure you know something about file types if you have made it this far. Simply put, make sure your files have the .php extension or else the server won’t process the code. If PHP is your first language other than HTML, CSS, and JavaScript, you will realize that PHP isn’t nearly as forgiving. Be consistent and use the proper syntax. Enough chatter, let’s write our first PHP script!

Example
<html>
    <body>
        <h3>My First PHP Code</h3>
        <?php
            echo "I am awesome!";
        ?>
    </body>
</html> 
Result I am awesome!

The command echo is one of the ways PHP can output content. So, basically we used the opening <?php tag to indicate that were starting to use PHP code. Then, we echo a string “I am awesome!”, which you are. And of course, we end our only statement with a standard ;. Finally, we tell the server that we no longer want to use PHP code and we close it with the ?> tag.

If you have this idea mastered, continue on to learn about the fundamental stones to craft a master PHP website.



Link/cite this page

If you use any of the content on this page in your own work, please use the code below to cite this page as the source of the content.

  • Stewart, Suzy. "Introduction". After Hours Programming. Accessed on March 16, 2024. https://www.afterhoursprogramming.com/tutorial/php/introduction-php/.

  • Stewart, Suzy. "Introduction". After Hours Programming, https://www.afterhoursprogramming.com/tutorial/php/introduction-php/. Accessed 16 March, 2024.

  • Stewart, Suzy. Introduction. After Hours Programming. Retrieved from https://www.afterhoursprogramming.com/tutorial/php/introduction-php/.



0 thoughts on “Introduction”

  1. Just had a quick question.

    Do HTA’s support PHP? I tried running a function using an input button, but when I try running the function I get an alert saying that "PHPTest() is null."

    This is what I have written:

    <html>
    <head>
    <title>New HTA</title>
    <HTA: Application>
    <link rel="stylesheet" type="text/css" href="C:\Styles\style.css">
    </head>

    <?PHP

    function PHPTest()
    {
    echo "PHP Test";
    }

    ?>

    <body bgcolor="lightsteelblue">
    <div class="button_format">
    <form>
    <input type="button" name="phptestbutton" value="PHP Test" onClick="PHPTest()">
    </form>
    </div>
    </body>
    </html>

    ————————————————————————————————————

    I also tried writing:

    <?PHP

    echo "Test"

    ?>

    inside the "body" tags, but still nothing. Anyone have any advice?

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.