parsing php files into html?

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
 
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.
 
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
 
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.
 
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
 
You mean the styling?

If so is the styling working on nothing at all? Or just on my quote thingy?
 
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.
 
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
 
that didnt really work? is there any way i can run it locally but not have to move all of my website?

Z
 
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"); ?>
 
@ 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
 
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 :/
 
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
 
Back
Top