Print Reseller Scheme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

parsing php files into html?

Discussion in 'Website Design Forum:' started by bentzak, Nov 25, 2009.

  1. bentzak

    bentzak Senior Member

    Hi,

    i am putting a little random quote generator built using php, into a page built using html and css. i have found links on the internet explaining how to do this, but it seems you need to know a bit more than i do to figure it out! can anyone help me? this web design just gets trickier and trickier i tell thee! also while im here, i want to do the same to build a contact page form, is that doable? or is there a far simper way to be doing this?

    Cheers,

    Zak
     
  2. Harry

    Harry Senior Member

    I dunno what you mean. You want to output html code in a php file? There are several ways:

    PHP:
    <?php
      $variableName 
    'foo';
    ?>

    <?php
      
    if($variableName == 'foo'){
        echo 
    "<p>bar</p>";
      }
    ?>

    <?php
      
    if($variableName == 'foo'){
    ?>
    <p>bar</p>
    <?php
      
    }
    ?>
    These both output:

    HTML:
    <p>bar</p>
    
    Although I'm not 100% sure what you mean, like I said.

    However, if by 'random quote generator' you mean every time you refresh the page you get a new quote then you might want something like this:

    PHP:
    <?php
        $quotes 
    = array(
            array(
    'quote' => 'quote one''name' => 'timmy'),
            array(
    'quote' => 'quote two''name' => 'bob'),
            array(
    'quote' => 'quote three''name' => 'allen')
        );
        
    shuffle($quotes);
    ?>
    <blockquote>
        <p><?php echo $quotes[1]['quote']; ?> <strong><?php echo $quotes[1]['name']; ?></strong></p>
    </blockquote>
    EDIT:

    I think I may have just wasted a lot of time there :(
    More specifics please.
     
  3. bentzak

    bentzak Senior Member

    i think the opposite is what i want. i have already finished the page in hmtl, using css. so its all layed out with space to put he random quote bit in. i got the code for the generator which works fine in its own php file, but i dont know what i need to do so the php quotes apear on the html page,

    i dunno if that makes sense? or if its possible!

    Z
     
  4. Harry

    Harry Senior Member

    Did you get the code as third party or was it written specifically for you? If it was third party then delete it all anyway. Use mine, that's free and I'm here to give support with it :D

    Say your random quote is to appear in a page called about.html.

    Simply change it to about.php, paste the above in where you'd like it to appear et voila. Job's a goodun.
     
  5. bentzak

    bentzak Senior Member

    did the above, instead of just a quote all of the code appears?

    Z
     
  6. Harry

    Harry Senior Member

    Are you a) running on a PHP server and b) renaming files to .php?
     
  7. bentzak

    bentzak Senior Member

    ah, i wasnt running through a php server, just put it on there, but my whole layout has gone? all the content, but no layout???

    Z
     
  8. bentzak

    bentzak Senior Member

    but the quote did work

    Z
     
  9. Harry

    Harry Senior Member

    You mean the styling?

    If so is the styling working on nothing at all? Or just on my quote thingy?
     
  10. bentzak

    bentzak Senior Member

    yeah the styling, not on anything

    Z
     
  11. Harry

    Harry Senior Member

    That is weird. Are you running a local server? Are your links definitely pointing to the right place? That code won't affect anything to do with styling.
     
  12. bentzak

    bentzak Senior Member

    aha! could be on to something there! im doing it through xampp localy, do i ned to put my whole rouut folder into the htdocs folder? that would make sense! i will try it.

    Z
     
  13. bentzak

    bentzak Senior Member

    that didnt really work? is there any way i can run it locally but not have to move all of my website?

    Z
     
  14. bentzak

    bentzak Senior Member

    got it going! but only the one page? is there a way i can run it from my rootfolder?

    Z
     
  15. Harry

    Harry Senior Member

    Save the code I gave you in a file called quotes.php in a folder called includes in your root. Wherever you'd like to use it on your site:

    PHP:
    <?php include("/includes/quotes.php"); ?>
     
  16. I did a random quote generate in PHP and JavaScript for TNA Wrestling at www.boundforglory5.com.

    If that's the type of thing you're after then drop me a line and I'll send you the files with an explanation.
     
  17. bentzak

    bentzak Senior Member

    @ mcb, im trying to do it with out using javascript, its more of an added feture really, so i dont want to loose accessibility.

    @ harry, when i changed the quotes for the quote generator the whole page disapered and came up with this,

    Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /Applications/XAMPP/xamppfiles/htdocs/rootfolder web/home/index.php on line 186

    i deleted the extra quotes i put in, and it worked again, what do i need to do to get it working with more??
    any ideas?
    also i dont know if my local server is set up right, but when i load my website it goes to a page that says, object not found, but if i then click on the localserver tab it goes to the folders, and i can get to the error above. how do i get it so it finds it?

    Z
     
  18. Harry

    Harry Senior Member

    It may because you're leaving a comma on your last quote array:

    PHP:
    <?php
        $quotes 
    = array(
            array(
    'quote' => 'quote one''name' => 'timmy'), //COMMA HERE
            
    array('quote' => 'quote two''name' => 'bob'), //COMMA HERE
            
    array('quote' => 'quote three''name' => 'allen'//NO COMMA HERE
        
    );
        
    shuffle($quotes);
    ?>
    as for your other issue, I don't know as I can access your server :/
     
  19. bentzak

    bentzak Senior Member

    yep, thats that sorted, its all working fine, except for having to go through the localhost folders through my browser to get to any of my pages, once im there they open fine and link fine, but not sure why its doing it, oh well, cheers for that, appreciate you taking the time to reply! truly helpfull, and i have learned a fair bit as well! bonus,

    Z
     
  20. Harry

    Harry Senior Member

    No worries :D

    And the server thing could be anything, I really have no idea.
     

Share This Page