Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embedding the entire HTML within PHP

3 views
Skip to first unread message

Domestos

unread,
May 17, 2006, 6:10:31 PM5/17/06
to
Hi all,

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" ? '


robert

unread,
May 17, 2006, 6:30:43 PM5/17/06
to

| 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?

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.


Drakazz

unread,
May 18, 2006, 1:46:15 AM5/18/06
to
I Never heard of a thing like pure php ;)

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.

Wenting, Marcel

unread,
May 18, 2006, 2:01:27 AM5/18/06
to
Domestos wrote:
> Hi all,
>
> 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?
>
What is the right way?
You dont echo a doctype, so you example isnt right ;-)
You example isn't wrong, but will be completely parsed by PHP.
This will consume more cpu power than when using HTML outside the php tags
I always prefer to keep html and php seperated as much as possible,
like:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Whatever</TITLE>
</HEAD>
<BODY>
<TABLE>
<?
for ($i=1; $i<100;$i++){
?>
<TR>
<TD><?=$i; ?></TD>
</TR>
<?
}
?>
</TABLE>
</BODY>
</HTML>
This keeps my code clean & fast, but it also just my way of working

Drakazz

unread,
May 18, 2006, 2:07:53 AM5/18/06
to
This code doesn't look any cleaner, to me.

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 ?> !!!

Martin Jay

unread,
May 18, 2006, 7:16:18 AM5/18/06
to
In message <rbNag.3300$bW5...@newsfe2-gui.ntli.net>, Domestos
<never.you@mind.?.invalid> writes

>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?

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

Drakazz

unread,
May 18, 2006, 1:55:47 PM5/18/06
to
Martin Jay: if you had read my post, then you wouldn't have written
this one.
Your coding is not nice. Use templates and no HTMl in your coding. Make
it flexible, eh?

robert

unread,
May 18, 2006, 2:11:00 PM5/18/06
to

"Drakazz" <vykintas....@googlemail.com> wrote in message
news:1147974947....@j55g2000cwa.googlegroups.com...

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


Wenting, Marcel

unread,
May 18, 2006, 2:30:21 PM5/18/06
to
Dear Drakazz,

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

Martin Jay

unread,
May 18, 2006, 3:17:37 PM5/18/06
to
In message <1147974947....@j55g2000cwa.googlegroups.com>,
Drakazz <vykintas....@googlemail.com> writes

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

Drakazz

unread,
May 18, 2006, 4:53:48 PM5/18/06
to
> 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.
:)))))))
LOL
Templating engines are used to separate the actual application code
from the output. This allows greater deal of flexibility as well as if
OOP is added.

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/

robert

unread,
May 18, 2006, 5:22:57 PM5/18/06
to

"Drakazz" <vykintas....@googlemail.com> wrote in message
news:1147985628.0...@i40g2000cwc.googlegroups.com...

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.


Drakazz

unread,
May 18, 2006, 6:47:22 PM5/18/06
to
Hm, what?:))
I am talking about template caching, not the output caching, or
browser's cache
I am not a noob if anything :)

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.

Message has been deleted

robert

unread,
May 19, 2006, 4:15:51 PM5/19/06
to

"Drakazz" <vykintas....@googlemail.com> wrote in message
news:1147992442....@i39g2000cwa.googlegroups.com...

| Hm, what?:))
| I am talking about template caching, not the output caching, or
| browser's cache
| I am not a noob if anything :)

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


Drakazz

unread,
May 20, 2006, 3:15:22 AM5/20/06
to
Cool :)

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 :)

0 new messages