How to Add a Bullet in PHP

A bullet is used to make items in a list stand out from the rest of the text on a Web page. Use the "<ul>" and "<li>" HTML tags to create bulleted lists. You can use the PHP scripting language to add the values from an array to the list. If you use a PHP array to add values to a list, you only have to change one line to add or delete list items.

Instructions

    • 1

      Open a blank plain text file. Type the line "<?php" (without quote marks) to start the PHP script.

    • 2

      Enter this line to create the array that will be added to the unordered list:

      $values = array('apple', 'orange', 'pear', 'plum', 'grapefruit');

    • 3

      Type these lines to create the HTML document:

      echo "<html>";
      echo "<body>";
      echo "<h3> My Favorite Fruits</h3>".PHP_EOL;
      echo "<ul>";

    • 4

      Create the "While" loop that will print each of the list items to the screen. Each item will have a bullet before the value:

      $num=count($values);
      $i = 0;

      while ($i < $num){

      echo "<li>".$values[$i]."</li>".PHP_EOL;
      $i++;
      }

    • 5

      Close the list, the HTML document and the PHP script with this code:

      echo "</ul>";
      echo "</body>";
      echo "</html>";
      ?>

    • 6

      Save the file with a ".php" file extension.

Related Searches:

References

Resources

Comments

Related Ads

Featured