How to Print a String of Numbers in PHP

The PHP programming language is used to embed interactive elements in Web pages. PHP has many features in common with mainstream programming languages, allowing you to create powerful and interactive websites. If you are getting started with the PHP language, you should try something simple to get a taste for the syntax. A suitable first PHP program is one that prints a string of numbers. You can write this program fairly quickly and get a feel for PHP development.

Things You'll Need

  • Computer with PHP server or an online PHP interpreter (see Resources)
Show More

Instructions

    • 1

      Decide how you will run your PHP code. If you have a PHP server, you can execute code using PHP files. If you do not have access to a PHP server, you can use an online PHP interpreter.

    • 2

      Begin your PHP program with the following statement:

      <?php

    • 3

      Declare a string containing numbers. A string is a data type that can store text, symbols and numbers. The PHP string declaration syntax uses a dollar sign in front of the string variable name. You can set the string equal to a numeric value, using the assignment operator as follows:

      $str = '0123456789';

    • 4

      Print the string of numbers using the print function like this:

      print($str);

    • 5

      Conclude your PHP program with the statement below.

      ?>

      Your program is now ready to be tested on your PHP server or online PHP interpreter. The program will output the sequence of numbers chosen in Step 3.

Related Searches:

References

Resources

Comments

Related Ads

Featured