php in html
Moderator: General Moderators
php in html
how do u echo a value in the middle of a html file? what is the line of code? does the whole file need to be brackated by php files
Code: Select all
<html>
<head>
<title>Some Title</title>
</head>
<body>
..more html here...
<b>Hello <?php echo $username ?></b>
...more html...
<i>Goodbye <?php echo $yellowbrickroad ?></i>
</body>
</html>hmm
doesnt seem to work. the field is just blank and nothing is there. how does the php value $username know to point to the sql field which stores its value. is this done in the general php login script or is it done at runtime in the php file internally?
Re: hmm
You'de generally do all you database work/whatever outside of the view/template/html. For example you might have a getuser.php file which does whatever database queries it needs to do and assigns the values, e.g $username. Then getuser.php might do an require_once 'user.php'; where user.php is of the format above...your html with php 'embedded'duranike wrote:doesnt seem to work. the field is just blank and nothing is there. how does the php value $username know to point to the sql field which stores its value. is this done in the general php login script or is it done at runtime in the php file internally?
The PHP code you write assigns them.duranike wrote:ok i understand so far but what actually calls or assigns the value in our html page?
Here's a simple example:
page1.php
Code: Select all
$username = 'Ford Prefect';
require_once 'page2.php';Code: Select all
echo 'Helloooooo '.$username;ok. i think i see where im going wrong. i guess the problem is that we have an html file that is very complicated. how can we use it as a php file? i think i have read that u can put a code like "{php} ..html... {/php}" ( { = [) and then u can work it as long as u rename it blahblah.php. any help or guidance? thanks for your time and patience. by the way, cool avatar.
Just rename it to whatever.php. As long as it has a .php extension it should, by default, be parsed ok using the standard php tags. That is <?php ... ?>
You can jump in and out of php mode whenever you want so the whole file doesn't need to be withing php tags..just the php bits.
So you can have..
lots of html here...
<?php some php bits here ?>
more html
<?php some more php ?>
etc..
{php} and {/php} sounds like template specifc tags, something like Smarty?
You can jump in and out of php mode whenever you want so the whole file doesn't need to be withing php tags..just the php bits.
So you can have..
lots of html here...
<?php some php bits here ?>
more html
<?php some more php ?>
etc..
{php} and {/php} sounds like template specifc tags, something like Smarty?