473,387 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Best Method using PHP & HTML ??

What is the best method for creating a Web Page that uses both
PHP and HTML ?

<HTML>
BLA
BLA
BLA
BLA
BLA
<?PHP
BLA
BLA
BLA
BLA
BLA
?>

</HTML>
OR

<?PHP
Echo "BLA"
Echo "BLA"
Echo "BLA"
Echo "BLA"
?>

OR

<?
Print "BLA"
Print "BLA"
Print "BLA"
Print "BLA"
?>

Thanks
Jul 16 '05 #1
10 4184
> What is the best method for creating a Web Page that uses both
PHP and HTML ?


There are a number of different ways of doing this, and I think your choice
really depends on how you would like to do it. My personal favourite is not
to include any HTML at all and just create PHP variables that contain my
HTML. Then at teh end of teh document I just use echo $output; This wouldn't
work so well in cases where you want to flush the output back to the user as
the script is being processed, but for short scripts this works well for me.

Jamie
Jul 16 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Mon, 30 Jun 2003 10:42:42 +0100, Kevin
Thorpe <ke***@pricetrak.com> amazingly managed to produce the
following with their Etch-A-Sketch:
James wrote:
What is the best method for creating a Web Page that uses both
PHP and HTML ?
If you are a programmer then you are probably happier staying
inside the php tags and using print/echo to generate your HTML.

I work differently. I write the bulk of my code at the top of the
document then drop out of the php tags to output the html with as
little php in there as possible. This lets me hand a rough but
functional document to my colleague who styles and polishes it in
DreamWeaver. If you take this a step further you can include the
html to allow
alternative languages / representations.

<?php include('library.inc');

loadobject($_REQUEST['id']);
?>
<html>
<body>
<?=object['id']?>

^^^^^^^^^^^^^^^^^
</body>
</html>

And if the server is configured for XML (ie: short tags disabled)
this would fall over.

The biggest thing to strike me here for this example, was that you
use '<?php' for the initial instance, yet '<?' for the second.

One of the biggest parts of coding, is style and consistency =)

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwAPTmfqtj251CDhEQIE+QCglmHcOaBbjDscnB2gULebsd 4WfKcAoOWb
nW4s8jv0O0sEQzefYhiVYfpp
=hglr
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #3
On Mon, 30 Jun 2003 08:45:36 +0000 (UTC), James @ nothere.com (James) hath writ:
What is the best method for creating a Web Page that uses both
PHP and HTML ?


snip.....8<

All the previous comments are On Target.
Another point:
It Depends.
If you control the server, that's One Thing.
How-some-ever, on one server site where I `manipulate` some
web pages, .phtml and/or .shtml do not work for embedded
<$php tags. I have no recourse but to bundle each target
page up in a .php.

Jonesy
--
| Marvin L Jones | jonz | W3DHJ | OS/2
| Gunnison, Colorado | @ | Jonesy | linux __
| 7,703' -- 2,345m | config.com | DM68mn SK
Jul 16 '05 #4
James wrote:
What is the best method for creating a Web Page that uses both
PHP and HTML ?

<HTML>
BLA
BLA
BLA
BLA
BLA
<?PHP
BLA
BLA
BLA
BLA
BLA
?>

</HTML>
OR

<?PHP
Echo "BLA"
Echo "BLA"
Echo "BLA"
Echo "BLA"
?>

OR

<?
Print "BLA"
Print "BLA"
Print "BLA"
Print "BLA"
?>

Thanks


If you needed to output a lot of variables in the HTML, then I would suggest
echo. However, if it were only a few, then you could do:

<?
$variable = "value";
?>
<html><head></head><body>
<b><?= $variable ?></b>
</body></html>

--
Regards,
Zach Nakaska
Jul 16 '05 #5
Zach Nakaska wrote:
If you needed to output a lot of variables in the HTML, then I would suggest
echo.


Based on what? If you're talking about readability of code, I agree
wholeheartedly. However, it says somewhere on the PHP site (though I
don't have time to look right now to cite my source) that escaping into
HTML (or, out of PHP, depending on your perspective) to print static
text is actually faster than echoing it.

Jul 16 '05 #6
Kevin Thorpe <ke***@pricetrak.com> wrote in message news:<3f***********************@news.easynet.co.uk >...
James wrote:
What is the best method for creating a Web Page that uses both
PHP and HTML ?


I work differently. I write the bulk of my code at the top of the
document then drop out of the php tags to output the html with as little
php in there as possible. This lets me hand a rough but functional
document to my colleague who styles and polishes it in DreamWeaver. If
you take this a step further you can include the html to allow
alternative languages / representations.


My PHP "style" has evolved over a couple of years and it's taken on
this form with all the algorithm stuff at the top of the page before
the <head>. I then just drop in small bits of PHP in the HTML.

Using PHP to echo complex HTML is painful as you end up escaping all
the " and having 50 lines of $html .= "" is time consuming and the
layout is more fixed. If you stick to HTML you can still edit the
layout with Dreamweaver and I even use PHP to show/hide blocks of
HTML, i.e

<?
if ($displaythis) {
?>
<table ...
.... <td><?=$message?></td>
</table>
<?
} else {
?>
<table ...
.... <td><?=$message?></td>
</table>
<?
}
?>

This makes the whole process so much easier and seems to be the best
balance of HTML editability (with Dreamweaver) and power of PHP.
Jul 16 '05 #7
James wrote:
What is the best method for creating a Web Page that uses both
PHP and HTML ?


I agree with both of the others that it all comes down to personal
style. I usually have my main pages as pure php control structures that
include various html files for outputing the data. This means that you
can open up both files in something like dreamweaver and edit them
independantly. Depends on the site, depends on your style.

Jul 16 '05 #8
In message <bf**************************@posting.google.com >, Paul
Liversidge <pa*************@hotmail.com> writes
Using PHP to echo complex HTML is painful as you end up escaping all
the " and having 50 lines of $html .= "" is time consuming and the
layout is more fixed.
That's what

echo <<<EOT
<!-- my html goes here using ", '
and $variables as appropriate -->

EOT;

is for :)
If you stick to HTML you can still edit the layout with Dreamweaver and
I even use PHP to show/hide blocks of HTML, i.e


I do this too - the designers here use Dreamweaver and so I code my
pages to enable them to make amends without needing my input.

Rob...

--
Rob Allen
Jul 16 '05 #9
On 30 Jun 2003 14:35:27 -0700, pa*************@hotmail.com (Paul
Liversidge) wrote:
Kevin Thorpe <ke***@pricetrak.com> wrote in message news:<3f***********************@news.easynet.co.uk >... Using PHP to echo complex HTML is painful as you end up escaping all
the " and having 50 lines of $html .= "" is time consuming and the
layout is more fixed.
That's why I use ' instead of " for HTML attributes.
If you stick to HTML you can still edit the
layout with Dreamweaver and I even use PHP to show/hide blocks of
HTML, i.e


I use CSS for layout which keeps the HTML simple and therefore my PHP,
too.

--
David (please modify address to david@ before replying!)
Jul 16 '05 #10
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Tue, 01 Jul 2003 16:16:03 +0100, David
Mackenzie <dc*@tarbrax.freeserve.co.uk> amazingly managed to produce
the following with their Etch-A-Sketch:
On 30 Jun 2003 14:35:27 -0700, pa*************@hotmail.com (Paul
Liversidge) wrote:
Kevin Thorpe <ke***@pricetrak.com> wrote in message
news:<3f***********************@news.easynet.co.u k>...
Using PHP to echo complex HTML is painful as you end up escaping
all the " and having 50 lines of $html .= "" is time consuming and
the layout is more fixed.


That's why I use ' instead of " for HTML attributes.

That's what the HEREDOC code is for ;)

If you stick to HTML you can still edit the
layout with Dreamweaver and I even use PHP to show/hide blocks of
HTML, i.e


I use CSS for layout which keeps the HTML simple and therefore my
PHP, too.

Only fools use WYSINWYG editors.. regardless of how code is split up
=)

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwKlAWfqtj251CDhEQJHEACcDTvjsfiTSmzLMWeJuj0mpW RKJUsAnj26
sqZIfNt3rhLeWMqmtlcrOv/g
=GI7/
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Amilcar | last post by:
Hi: I have a problem: I've a page that sends an encrypted password, using MD5, to a PHP file, which is able to compare such MD5 encrypted password with an encryption stored on a data base. But...
3
by: Derek Fountain | last post by:
Just asked a question regarding this little bit of XSL: --- <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> ...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
3
by: beanweed | last post by:
I have an Oracle Procedure that returns xml. There was an exception thrown when I tried to load an XmlDocument (using LoadXml(String)) because the value returned from Oracle had an exclamation mark...
1
by: Jim Carlock | last post by:
Let's not argue about semantics. Let's talk about semasiology. Do specifications exist for using mixed case, upper case, lower case for the contents of the method employed? My own preferences...
13
by: mark4asp | last post by:
When I write a url in xhtml, with an unencoded ampersand, like this: http://localhost:2063/Client/ViewReport.aspx?Ref=58&Type=SUMMARY the xhtml sytax checker correctly indicates an error,...
2
by: bips2008 | last post by:
The code seems to work fine in other browser but in IE it throws this error. This is very urgent for me and any help would be greatly appreciated For your convienence i have posted the code for the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.