473,390 Members | 953 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,390 software developers and data experts.

Outputting formatted html from php scripts

Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?

Craig

Jul 17 '05 #1
12 2093
I do for the most part, but I have never had an ugly script becouse of it.

I do not indent my tables too far in, some times I will restart the nesting
at colom 0 for a table.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Craig Thomson" <cr***@spam.free> wrote in message
news:76********************************@4ax.com...
Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?

Craig

Jul 17 '05 #2
sorry, I hit send too fast, here is the rest of my post.

sometimes my tables outout like this:

<table>
<tr>
<td>

<table>
<tr>
<td>stuff</td>
</tr>
</table>

<td>
</tr>
</table>

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Craig Thomson" <cr***@spam.free> wrote in message
news:76********************************@4ax.com...
Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?

Craig

Jul 17 '05 #3
Craig Thomson wrote:
Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?


I don't :)

I might put a few "\n" here and there (usually after </tr> or <br/>) but
no indenting for the next line. If I want to look at the HTML produced I
tidy it first with
HTML Tidy ( @ http://www.w3.org/People/Raggett/tidy/ )
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #4
On Mon, 16 Feb 2004 05:47:05 GMT, Craig Thomson <cr***@spam.free>
wrote:
Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?


Personally, I don't bother.

My PHP code is nicely indented, so debugging is easy from the server
end. Also, I try and output fairly clean HTML (no nested tables, etc)
which makes dubugging from the client end easier.

I don't see the point in cluttering up one's script with \n's and
\t's. The browser doesn't need them and it saves a few bytes bandwidth
;-)

Here's a tip: Single quotes can be used in HTML for attributes, so you
can write:

print("<img src='whatever.png' alt='Whatever'>"); // nice.

as opposed to:

print("<img src=\"whatever.png\" alt=\"Whatever\">"); // ugly.

--
David ( @priz.co.uk )
Jul 17 '05 #5
David Mackenzie writes:
Here's a tip: Single quotes can be used in HTML for attributes, so you
can write: print("<img src='whatever.png' alt='Whatever'>"); // nice. as opposed to: print("<img src=\"whatever.png\" alt=\"Whatever\">"); // ugly.


Good tip. Here's another one. If ?> is followed immediately by a
newline then the newline will not be output. For example:

<?php echo "cat"; ?>
fish

Will write this:

catfish

If you follow the end-of-line ?> with a space you get this:

cat
fish

--

__o Alex Farran
_`\<,_ Analyst / Programmer
(_)/ (_) www.alexfarran.com

Jul 17 '05 #6
David Mackenzie wrote:
Here's a tip: Single quotes can be used in HTML for attributes, so you
can write:

print("<img src='whatever.png' alt='Whatever'>"); // nice.


Why use double quotes for PHP at all?

print('<img src="whatever.png" alt="whatever">'); // nicer IMHO
though, if I'm not using the return value of print() i prefer echo()
using the parenthesis-less syntax

echo '<img src="whatever.png" alt="whatever">';
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7
On 16 Feb 2004 12:19:23 GMT, Pedro Graca <he****@hotpop.com> wrote:
David Mackenzie wrote:
Here's a tip: Single quotes can be used in HTML for attributes, so you
can write:

print("<img src='whatever.png' alt='Whatever'>"); // nice.
Why use double quotes for PHP at all?


I'm used to using double quotes for string literals from other
languages.
print('<img src="whatever.png" alt="whatever">'); // nicer IMHO


They're both preferable to \"whatever\".

--
David ( @priz.co.uk )
Jul 17 '05 #8
Pedro Graca <he****@hotpop.com> wrote in news:c0qcgb$19rnoe$1@ID-
203069.news.uni-berlin.de:
David Mackenzie wrote:
Here's a tip: Single quotes can be used in HTML for attributes, so you
can write:

print("<img src='whatever.png' alt='Whatever'>"); // nice.


Why use double quotes for PHP at all?

print('<img src="whatever.png" alt="whatever">'); // nicer IMHO


But that won't work if you need to interpolate the values of variables into
the generated output.
Jul 17 '05 #9
Eric Bohlman wrote:
Pedro Graca <he****@hotpop.com> wrote in news:c0qcgb$19rnoe$1@ID-
203069.news.uni-berlin.de:
David Mackenzie wrote:
Here's a tip: Single quotes can be used in HTML for attributes, so you
can write:

print("<img src='whatever.png' alt='Whatever'>"); // nice.


Why use double quotes for PHP at all?

print('<img src="whatever.png" alt="whatever">'); // nicer IMHO


But that won't work if you need to interpolate the values of variables into
the generated output.


No, it will not. But I prefer to not interpolate

<?php
$oldname = 'Pedro Graca';
echo '<input type="text" name="username" value="', $oldname, '"/>';
?>

is how I do it.
I agree that

<?php
$oldname = 'Pedro Graca';
echo "<input type='name' name='username' value='$oldname'/>";
?>

looks more like HTML than my preferred version, but I find it more
difficult to know what is being printed when interpolation is used.
I don't care for HTML looking scripts :)

One of the first things I do to scripts of other people is
"deinterpolate" it :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #10
I use a composition of objects to produce the output, usually in
combination with files that are included by the objects.

The included files contain most of the lay out and are mostly in html
mode. I usually keep the html in each file properly formatted to make it
readable. I do not bother about the formatting of the final output that
is produced by the objects together. I don't want to becuase that would
make it harder to reuse the objects in whatever combination i like.

If i need to see the overall object composition structure in the output,
i switch on the object's debugging mode so that the start and end of the
output of each composing object is announced in html comments.

Greetings,

Henk Verhoeven.

Craig Thomson wrote:
Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?

Craig


Jul 17 '05 #11
For a while I try to use heredoc, but soon gave up. Nowaday I do a lot of
<?=$var?> and <? foreach():?>...<? endforeach; ?>. Makes fixing HTML layout
issues a little easier than doing echos.

My HTML forms tend to look like this:

<input name="hello" value="<? echo htmlspecialchars($hello); ?>">

<? $checked = araay($which => "checked"); ?>
<input name="which" type="radio" value="a" <?=$checked['a']?>>
<input name="which" type="radio" value="b" <?=$checked['b']?>>
<input name="which" type="radio" value="c" <?=$checked['c']?>>

<? $selected = array($cow => "selected"); ?>
<select name="cow">
<option value="3" <?$selected[3]?>>Mad</option>
<option value="4" <?$selected[4]?>>Dead</option>
<option value="5" <?$selected[5]?>>Tastes like chicken</option>
</select>

Uzytkownik "Craig Thomson" <cr***@spam.free> napisal w wiadomosci
news:76********************************@4ax.com...
Do people generally try and output nicely formatted html from their
scripts?

I have been trying to, with variable indenting for tables etc. It
makes it easier to see the html and perhaps debug it, but it can make
ugly looking scripts.

What's the general consensus?

Craig

Jul 17 '05 #12
Eric Bohlman wrote:
Pedro Graca <he****@hotpop.com> wrote in news:c0qcgb$19rnoe$1@ID-
203069.news.uni-berlin.de:

David Mackenzie wrote:
Here's a tip: Single quotes can be used in HTML for attributes, so you
can write:

print("<img src='whatever.png' alt='Whatever'>"); // nice.


Why use double quotes for PHP at all?

print('<img src="whatever.png" alt="whatever">'); // nicer IMHO

But that won't work if you need to interpolate the values of variables into
the generated output.


print "<img src=\"whatever.jpg\" alt=\"$description\">\n";

no problemo.

/m

Jul 17 '05 #13

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

Similar topics

4
by: kingofkolt | last post by:
im trying to let a user download a file from my website, for example a picture. i dont want the user to have to right-click and do save-as, but instead i want a window to popup (the window with...
5
by: Paul Lamonby | last post by:
Hi, I am generating a HTML formatted email in PHP, but I am getting the most bizarre error, it will randomly delete characters out of the HTML code while in transit to the address, therefore...
1
by: Robert V | last post by:
Hi all, another area I could use some help with is changing submitted data based on the data conditions ... I will elaborate. I have a form textarea where a user can type in some text. This text is...
9
by: Nick Forrington | last post by:
Hi, I'm making a program and have a static Console class that I'm using to output things, these get sent to the console and also to the graphics on screen (I'm using SDL). One thing I'm having a...
3
by: Craig Petrie | last post by:
Hi, I have a large table in Word 2003 that has formatted text in the cells and wish to read and convert a cells formatted contents to html output via vb.net code. The formatting contains the...
1
by: robbiesmith79 | last post by:
Just so this is out there on the web, I battled the past 24 hours about this. Background info... I developed a ecommerce website in PHP 4 on a shared linux hosting plan from GoDaddy and had the...
4
by: cybervigilante | last post by:
I sent HTML formatted email, using PHP, to my Yahoo address from my server, and it came out fine, styles and all. I sent it to my gmail address to test it and all I see is the raw html code. But I...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
2
by: Artie | last post by:
Hi, I've searched the web but can't find a solution to an apparently really simple problem. My app contains an HTML string and I need to be able to invoke the Print Dialog to print the HTML...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.