Jump to content

PHP newbie, simple question


timbo6585

Recommended Posts

hello all,

 

i have a good foundation in HTML, no PHP knowledge.  the script im about to show you someone kindly gave me.  i copied and pasted it into notepad, saved it as a php, then opened it in firefox thinking it would work normal and i would just have to fill in the blanks.  no such luck, it just comes up completely blank.  i've tried tweaking a few things and the browser seems to get mad and just display the whole entire code making me know i screwed something up.  my aim here is to just make a simple little script that will display a random fact every time the page is refreshed.  here is the code, thank you for the help.

 

<?php
switch (rand(1,5)){
    case "1":
        echo "html goes here. This is item 1";
        break;    
    case "2":
        echo "html goes here. This is item 2!";
        break;    
    case "3";
         echo "html goes here. This is item 3";
        break; 
    case "4";
         echo"html goes here. This is item 4";
          break;
    case "5";
         echo"html goes here. This is item 5";
          break;
           
}

?> 

Link to comment
https://forums.phpfreaks.com/topic/47993-php-newbie-simple-question/
Share on other sites

:-[ :-[ :-[no... i thought i could just open it up in a browser and have it display fine like i can with HTML, regardless of whether or not it's a server.  did i think wrong?  i do have a PHP based forum that i use, simple machine forum, and can throw it in there just to get a look at it.

PHP is executed server side (not like html which is rendered via a browser), so yes, you need a web server. You can set one up on your local machine to test code on.

 

Assuming your using a windows OS I would probably recommend setting up something like XAMPP. Otherwise, you'll need to install Apache and PHP separately.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.