473,324 Members | 2,124 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,324 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 2089
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.