|
Posted by Steve on 11/01/06 18:48
| Hi Martin,
|
| Thank you for your reply, I've solved it now with a suggestion from Steve,
| but thank you anyway for replying, I am very grateful. Re: the
structure,
| I've never been able to decide since starting to learn php whether it is
| better to print the html or break out of php into html then back in again,
I
| do know what you mean though it does look a little messy and unstructured.
| Your example definitely makes it easier to read. Point taken, and noted.
| Though with that said, I'd be interested to here others views on this,
| because as I've stated, I've been on the fence in deciding. And it's
always
| useful to know the pros and con's for both, and how others feel. This way
| it will give me a better understanding of which is best. I realise that
| when you need to print large amounts of html it's better to break out of
php
| to do it, but when it comes to the odd table I don't know which is best.
i use this as my guide:
always make sure your html output is sent to the browser in a completely
well formatted manner. such as indenting parent html nodes and further
indenting child nodes.
making sure that html output does not require one to wrap text when viewing
source from a page.
(these two will save you ooodles of time trying to debug output...it is easy
to do and makes you look professional in the process).
as for php, my goal is to have php parse as little as possible. this
includes using ' instead of " when i am not embedding php variables or
control characters in a string. ex. echo 'hello world', "hello world\n". as
a general rule though, you want to keep your php code seperate from your
html *as much as possible* and only mingle the two when necessary. btw, have
you heard of "short-tags"? rather than the long, drawn-out method of:
html<? echo $variable; ?>more html
short-tags provide the same output in this form:
html<?= $variable ?>more html
notice the equal sign, the lack of "echo", and the lack of the final
semi-colon. short-tags are enabled in php by default, but if they don't
work, you'll have to turn them on either in the php.ini or by calling
ini_set in your php script/page.
any of that help?
Navigation:
[Reply to this message]
|