Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Ghost

Platinum Coder
I want to share this easy beginner PHP tutorial for how to code Hello World in PHP! It is one of the easiest ways to learn a new programming language because it covers how to start your code block in the PHP file and show text on the page. You can read my full beginner PHP Hello World tutorial for all the different types of PHP programming, code, and functions you can learn just from a basic hello world guide. Using echo is the easiest way, but you can also use PHP's print statement.

Step 1) Create a PHP file
A PHP file is simply anything ending with the .php extension. Of course, you must have PHP enabled and set up correctly on your home computer or your server.
For my example, I will create 'HelloWorld.php' as my PHP script.

Step 2) PHP Script Code
You must make sure to start your code with the PHP open tag <?php
Similarly, you must end your PHP script with the end tag ?>

You can now write PHP code inside of the open and close tags.


How to code a PHP Hello World script:
PHP:
<?Php
echo "Hello World";
?>

Another way to say Hello World in PHP:
PHP:
<?Php
echo("Hello World");
?>

HTML with PHP is super easy! In fact, this was one main reason PHP was originally created. PHP Echo displays HTML on the page just as you would expect:
PHP:
<?Php
echo "<h1>How to Code Hello World in PHP</h1>";
echo "<p>As you will see, your PHP script can echo HTML and it will work as expected.</p>";
?>
As you can see, you can easily echo a string of text in the PHP script. HTML is allowed, so feel free to play around with <strong>bold text</strong>, or other formatted text like <h1>header text</h1>! PHP echo is very easy to use because it's short, sweet, and you do not have to declare the type of variable/data being output or the number of characters like you may in other more advanced languages.

You can even use variables in the echo statement...
PHP:
<?Php
$person = "Ghost";
$words = "Hello World!";
echo "$person says $words";
// page says: Ghost says Hello World!
?>
 

New Threads

Buy us a coffee!

Back
Top Bottom