I am currently writing pages that are pure PHP. i.e. they begin with the
<?php symbol.
I am embedding all the HTML within echo ' ' commands even the <HTML> <HEAD>
and <BODY> tags
i..e.
<?php
echo '<HTML><HEAD><TITLE>Title</TITLE></HEAD><BODY></BODY></HTML>';
?>
Is this the right way to do things? or should I be embedding PHP into the
HTML page?
--
Thanks,
Domestos
--------------------------------------------------------
'Why can't you make another word using all the letters in "anagram" ? '
six-one-half-a-dozen-the-other. as long as you format your code and comment
when necissary, i don't think anyone will beat you up for whichever method
you take.
btw, what is "pure" PHP? lol.
Domestos: You might want to create a PHP script that doesn't have any
HTMl in it at all?
Then I'd be very happy.
http://smarty.php.net/ will be helpful to you!
Thanks.
None of my new site scripts have html embeded in them, how's that?
for example, a bit of code:
elseif ( $site->rget['0'] === "activate" && isset($site->rget['1']) &&
ctype_alnum($site->rget['1']) ) {
$activation = new Activation($site->rget['1']);
logit();
if ( $activation->valid(&$site) === true ) {
$site->setView("activation.successful");
}
else {
$site->setView("activation.error");
}
}
which is then passing variables to the $site and then the Smarty
template engine is being used to parse the output, which has embeded
HTMl in PHP, but it's automatically generated and saves time from
miximg HTMl with PHP, so your PHP scripts or HTML don't have to cry
when you need to make any changed.
And what's with the usage of <?= ?> and <? ?> ?! These are depreccated
now and wouldn't work with normal PHP compiles.
Always use <?php ?> !!!
The second option is probably the easiest way to do things. It will
make your documents easier to follow and debug too.
For example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hello World</title>
</head>
<body>
<?php echo "Hello world"; ?>
</body>
</html>
Sometimes it is convenient to include HTML within PHP, for example:
[some PHP]
echo "<p>".$paragraph."</p>";
[more PHP]
IMO in this sort of case, where you want to just output a small amount
of HTML (<p> and </p>), it's easier to include it in an echo.
--
Martin Jay
drak,
as much as i think m.j. is a waste of time in the world of php, i don't
think the use of smarty is a predicate qualification. most people hired for
a job don't know what smarty even is. i too believe in the seperation of
church and state...errrr...html and php, however, one should architect
pragmatically. some isp's don't have smarty installed nor will they. if your
company chooses to use it, it may have a problem hiring someone who can
program for it - this is especially difficult when consultants are brought
into the mix. that raises the price tag in most cases.
one can acheive that separation simply by employing oop design. that
minimizes intermingling and keeps your core business logic as completely
php...one layer up is the presentation layer where they do come together. i
just personally don't see the need for smarty in most cases. there are only
so many things one can do with web pages...and none of them are overly
difficult. repetative presentation tasks can be handled with out of the box
php...and a little forethought of design.
but that's just me. i have used smarty and do like what it allows. do i use
it on the job? no...and probably never will. either way, m.j. really
shouldn't write *anything*. ;^)
cheers,
me
You code does look nice, although only such a small part of code doesnt
say to much.
But I thought the question wasnt: "how to code nice in PHP together with
smarty?".
I dont use any template engines yet, I do see an advantage, but it's no
requisite for PHP.
I also recently compiled one of the latest PHP(5.x) versions, nothing
ordinary, just a regular ./configure, make, make install and the short
tags just work over here.
I totally agree that using <?php ?> is more nice, but dont talk about it
not working with normal compiles, coz it still does.
Marcel
Please quote what you're responding to, and attribute it correctly.
I hadn't read you message before I wrote mine.
Smarty is an interesting solution to the problem of separating code from
presentation (HTML), but IMO it doesn't make code look nicer or increase
flexibility.
--
Martin Jay
If you're wasting time makign a redesign, then it's your skills,
showing that your site is not flexible.
Using a template engine i can quiackly redesign the HTML code and CSS
without any problems.
In order for you to do anything, you'll need to edit yoru PHP scripts.
Smarty is a big advantage over others because it is much faster and
caching can be enabled too.
More info @ http://smarty.php.net/
you can cache in php too. they're called headers. ;^)
also, the html is SOMEWHERE...whether alongside php or in smarty, it's
SOMEWHERE. OOP gives flexibility not SMARTY. glad ur a fan though.
Smarty gives great deal of flexibility and OOP too. They work awsomely
together!
Smarty converts nice template code to PHP code meaning that the pages
do not need to use classi cugly str_replace or any other parsing
nonsense. If you enable template caching, the overall result will be
that the Smarty won't have to regenerate these pages meaning that
you'll benefit from faster page generation.
I am currently thinking of a way how to cache the PHP script state in
order to save time (not the output caching though :)).
This is more of Object caching allowing you to speed up the time and
save the query results etc. I haven't thought of that fully yet because
I don't have a lot of time at the moment.
Could you not use AOLbonics like "u", "r" or "ur" etc., because they
are not any kind of English language and are not understandable or
might be considered as disrespect to other users because you're too
lazy to write "you" and "are" at these people - is that the case maybe?
:(
Regards.
gotcha.
| Smarty gives great deal of flexibility and OOP too. They work awsomely
| together!
yeah, it is a good combo. i also like php with xml and xslt...which also
seperates php from the html/presentation side of things.
| Smarty converts nice template code to PHP code meaning that the pages
| do not need to use classi cugly str_replace or any other parsing
| nonsense. If you enable template caching, the overall result will be
| that the Smarty won't have to regenerate these pages meaning that
| you'll benefit from faster page generation.
| I am currently thinking of a way how to cache the PHP script state in
| order to save time (not the output caching though :)).
| This is more of Object caching allowing you to speed up the time and
| save the query results etc. I haven't thought of that fully yet because
| I don't have a lot of time at the moment.
best of luck.
| Could you not use AOLbonics like "u", "r" or "ur" etc., because they
| are not any kind of English language and are not understandable or
| might be considered as disrespect to other users because you're too
| lazy to write "you" and "are" at these people - is that the case maybe?
| :(
i assure you, laziness is not the case. it is merely short-hand. if it makes
you more comfortable and me more understandable, given non-native english
speaking audiences, i'll be happy to do away with the short-hand.
cheers,
me
I had a discussion about smarty on IRC. He is quite against Smarty.
I am not, but it's still much better to use PHP template, which would
do everything like a smarty generated output template, which is still
parsed as a php file.
Using smarty is only the advantage if you have separate designers from
coders, or you are too busy on a big project.
I am now going to the thinking bit, and need to creaqte a really good
way of object caching, where applications would work even faster!! :)
Server caching :)