473,507 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP to echo a line in html source...

Here an unusual one...

Say i am writing a few lines of code in php script as so...

<?php
echo '<table>';
echo '<tr>';
echo '<td> blah blah </td>';
echo '</tr>';
echo '</table>';
?>

On my html source the code looks like this...

<table><tr><td>blah blah</td></tr></table>

Is there anyway I can get each html tag on a seperate line in the html
source so it is nice and neat (easy readable)?

Thanks
Domestos

Aug 23 '05 #1
9 3403
On Tue, 23 Aug 2005 20:24:38 GMT, "Domestos" <ne*******@mind.net> wrote:
Here an unusual one...

Say i am writing a few lines of code in php script as so...

<?php
echo '<table>';
echo '<tr>';
echo '<td> blah blah </td>';
echo '</tr>';
echo '</table>';
?>

On my html source the code looks like this...

<table><tr><td>blah blah</td></tr></table>

Is there anyway I can get each html tag on a seperate line in the html
source so it is nice and neat (easy readable)?


echo "<table>\n";

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Aug 23 '05 #2
JDS
On Tue, 23 Aug 2005 21:36:30 +0100, Andy Hassall wrote:
echo "<table>\n";


Let me also point out that Andy used double-quotes. Doing this:

echo '<table>\n';

will not produce the same output.

I recommend that you not echo, line by line, large blocks of HTML like you
have done. Makes it quite hard to read (and debug or alter or update).

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Aug 23 '05 #3
Domestos wrote:
Here an unusual one...

Say i am writing a few lines of code in php script as so...

<?php
echo '<table>';
echo '<tr>';
echo '<td> blah blah </td>';
echo '</tr>';
echo '</table>';
?>

On my html source the code looks like this...

<table><tr><td>blah blah</td></tr></table>

Is there anyway I can get each html tag on a seperate line in the html
source so it is nice and neat (easy readable)?


How about:

<?php
$tmp = array();
$tmp[] = '<table>';
$tmp[] = "\t".'<tr>';
$tmp[] = "\t\t".'<td> blah blah </td>';
$tmp[] = "\t".'<tr>';
$tmp[] = '</table>';
echo implode("\n",$tmp)."\n";
?>

I use similar constructs all the time. It make for nice readable code.

Ken

Aug 23 '05 #4
> [snip]
<?php
echo '<table>';
echo '<tr>';
echo '<td> blah blah </td>';
echo '</tr>';
echo '</table>';
?>

[snip]

Is there anyway I can get each html tag on a seperate line in the html
source so it is nice and neat (easy readable)?


Many ways.
First one (using double quotes and escape sequence \n):

<?php
echo "<table>\n";
echo "<tr>\n";
echo "<td> blah blah </td>\n";
echo "</tr>\n";
echo "</table>\n";
?>

or:

<?php
echo "<table>\n<tr>\n<td> blah blah </td>\n</tr>\n</table>\n";
?>

or:

<?php
echo '<table>'."\n";
echo '<tr>'."\n";
echo '<td> blah blah </td>'."\n";
echo '</tr>'."\n";
echo '</table>'."\n";
?>

or escaping to HTML:

<?php
// some PHP code
?>
<table>
<tr>
<td> blah blah </td>
</tr>
</table>
<?php
// other PHP code
?>

or using multiline strings (and double quotes):

<?php
echo "<table>
<tr>
<td> blah blah </td>
</tr>
</table>
";
?>

or (probably) many more.
Hilarion
Aug 23 '05 #5
I suppouse to understand them I need to understand the significance between
doubles quotes and single quotes in php code...

Can any one help? or point me to some text

thanks for your help so far, the hardest part is choosing which one to use
and stick too...

Andy Mak

Aug 23 '05 #6
On Tue, 23 Aug 2005 20:59:51 GMT, "Domestos" <ne*******@mind.net> wrote:
I suppouse to understand them I need to understand the significance between
doubles quotes and single quotes in php code...


http://www.php.net/manual/en/language.types.string.php

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Aug 23 '05 #7
or using multiline strings (and double quotes):

<?php
echo "<table>
<tr>
<td> blah blah </td>
</tr>
</table>
";
?>


<snip>

That one thats worked for me is as follows... multiline string, with single
quotes. I needed to embed php variables into the string also... as
follows...
echo '<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="gfx/interface/win_'.$wincol.'_tl.gif" width="10" height="10"
border="0"></td>
<td><img src="gfx/interface/win_'.$wincol.'_t.gif" width="'.$winwid.'"
height="10" border="0"></td>
<td><img src="gfx/interface/win_'.$wincol.'_tr.gif" width="10" height="10"
border="0"></td>
</tr>
<tr>
<td><img src="gfx/interface/win_'.$wincol.'_l.gif" width="10"
height="'.$winhgt.'" border="0"></td>
<td width="'.$winwid.'" height="'.$winhgt.'" bgcolor="#393939">';
Aug 23 '05 #8
Domestos wrote:
<snip>
Is there anyway I can get each html tag on a seperate line in the html
source so it is nice and neat (easy readable)?

My favorite for large blocks of HTML hasn't been mentioned yet. It is
the "here document" structure for defining a string:

<?php
$something = "blah blah"; # just to show off variable interpolation

echo <<<EOHEREDOC
<table>
<tr>
<td> $something </td>
</tr>
</table>
EOHEREDOC;

?>

Check out 'PHP "Here document" tutorial' with Google. Unfortunately
this form of defining a string is not covered very well in the PHP
manual.

The here document preserves whitespace and newlines, and interpolates
variables in the same way doublequote strings do.

Aug 23 '05 #9
Domestos schrieb:
<table><tr><td>blah blah</td></tr></table>

Is there anyway I can get each html tag on a seperate line in the html
source so it is nice and neat (easy readable)?


Well, you CAN try to make it nice by yourself, but there's also the
possibility of letting software do that job. With "tidy" one can
prettyprint HTML code and there are possibilities do automagically use
it when sending HTML to the browser. There are extension to PHP that
allow for this. You should read a bit about using the output buffers or
the tidy extension.

As an appetizer, just have a look at this comment:
http://de.php.net/manual/en/ref.tidy.php#48981

AllOLLi
Aug 24 '05 #10

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

Similar topics

2
2160
by: lawrence | last post by:
Right now, over at www.monkeyclaus.org, the following script is getting to the 9th run through and dying after the line: echo "..."; You'll admit that is a strange place to die. I've hit...
1
2900
by: Chris Dean | last post by:
Hi I'm useing the php NUKE CMS and am designing a theme for it. this basically consists of the the main html structure of the page being produced line by line from php echo commands I have a...
6
3379
by: James Smith | last post by:
What's the difference between Echo and Print? J.
3
3981
by: Xenophobe | last post by:
I read a short thread at php.net regarding the use of ECHO. I have an HTML form with PHP variables to define each input value (if any.) For example: <input type='text' name='firstname'...
13
5206
by: comp.lang.php | last post by:
Other: <input name="school_type_other" size="30" maxlength="75" value="<?php if ($_POST) echo $_POST; else echo str_replace('"', '&quot;', str_replace('\\', '', $result->school_type_other)); ...
21
7796
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
2
1851
by: peridian | last post by:
I've gotten a really weird result crop up on my site, and I can't find any information on the web that it has been seen elsewhere. Given how weird this is, I guess it's probably a symptom of either...
1
2521
by: sheel331 | last post by:
Hello, I am new to coding in PHP, and had a question about a simple thing: I am trying to echo out the elements of an array for a sidenav in one of my HTML pages, and I can't seem to figure out...
32
2596
by: Request-1 | last post by:
hi folks, html coder here, new and terrified * of php!! aaaaaa! i'm trying to bury a JS script to rotate a photo, in a page i converted from html to php. the conversion went well, it was to...
0
7223
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
7114
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...
1
7034
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...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.