473,807 Members | 2,883 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 3423
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.u k :: 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",$t mp)."\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.u k :: 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="'.$winwi d.'"
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="'.$winh gt.'" border="0"></td>
<td width="'.$winwi d.'" height="'.$winh gt.'" bgcolor="#39393 9">';
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
2179
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 refresh several times and it keeps happening. When I view page source, the last thing that shows up is the "...". The date doesn't print, nor does the closing the div tag.
1
2913
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 javascript menu system I want to use which is held in an external ..js file so I try to echo out the relevent <script></script> startements to load up this file however it's not showing up on the page - however the static html version of the
6
3404
by: James Smith | last post by:
What's the difference between Echo and Print? J.
3
3992
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' value='<?php echo $FirstName; ?>'> I'm wondering if it makes any sense (performance and code-efficiency wise) to do as follows:
13
5222
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
7866
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
1871
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 a server-side setting, or something very subtle. I have some code that builds a MySQL statement to retrieve some records. The subsequent HTML displays the results. No problem. I then changed the statement to have a WHERE clause that reads: ...
1
2541
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 the syntax for appending the element of the array into the path to the file. Here is the code I have: <?php include 'c:\inetpub\webroot\sheel\template\navbar.html';
32
2659
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 use a php session cookie to stop the repeating of an embedded video file on a per session basis; i amended the php code to display a still pic if the session cookie value
0
9599
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10112
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4330
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 we have to send another system
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.