PHP Linebreaks, NOT <br />

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
randomblink
Forum Commoner
Posts: 51
Joined: Wed Jan 28, 2004 11:27 am
Location: Tulsa, Oklahoma, just this side of hell...
Contact:

PHP Linebreaks, NOT <br />

Post by randomblink »

Code: Select all

<?php
$html .= "<tr class="msgTitle_" . $messageType . "Message">";
$html .= "<td class="msgImageHolder" rowspan="2" onclick="flick( $jsScript );return false;">";
$html .= $imgHandler . $this->_msgReadYet( $message['read_yet'] ) . $this->_msgFromIcon( $message['alliance'] ) . "</td>";
$html .= "<td colspan="2">" . $message['title'] . " - [" . $message['date'] . "::" . $message['time'] . "]</td>";
?>
Ok...
This is sample code.
Return $html; gives me jumbled together HTML.
I am TRYING to create clean code for the output.
I want each HTML Tag to be on a newline in the resultant PHP->Output.
In other words, when I run the script... And I get an HTML page, I want to view source and SEE a clean HTML Code.

Can anyone help me out here?
I have tried nl2br, but this puts <br /> EVERYWHERE! No good... I just need each HTML Tag to be on a new line... HELP!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

\n
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

feyd wrote:\n
oh how short and simple ...bravo feyd bravo!
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

This is also a possibility:

Code: Select all

<?php
$html = '<table cellspacing="2" cellpadding="2" border="1">
<tr align="center">
    <td>This is</td>
    <td>also</td>
</tr>
<tr align="center">
    <td>a</td>
    <td>possibility</td>
</tr>
</table>
';

echo $html;
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

WaldoMonster wrote:This is also a possibility:

Code: Select all

<?php
$html = '<table cellspacing="2" cellpadding="2" border="1">
<tr align="center">
    <td>This is</td>
    <td>also</td>
</tr>
<tr align="center">
    <td>a</td>
    <td>possibility</td>
</tr>
</table>
';

echo $html;
?>
make sure you escape the single quotes when parsing variables..

for example

Code: Select all

<?php

html = 'this is escaping '. $foobar .' so the variable will get parsed';
?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Phenom wrote:
WaldoMonster wrote:This is also a possibility:

Code: Select all

<?php
$html = '<table cellspacing="2" cellpadding="2" border="1">
<tr align="center">
    <td>This is</td>
    <td>also</td>
</tr>
<tr align="center">
    <td>a</td>
    <td>possibility</td>
</tr>
</table>
';

echo $html;
?>
make sure you escape the single quotes when parsing variables..

for example

Code: Select all

<?php

html = 'this is escaping '. $foobar .' so the variable will get parsed';
?>
uhm... I dont see any reason there that he would need to escape anything for any variable. Where did that comment come from?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Its as the example used single quotes - which would just show $blah instead of what was held in the var. At least thats what i understand from it.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Yes thats true, but i was just asking why he posted that when he wasn't trying to pass a variable through or anything....
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Yeah true :P

(Just trying to get to 400 posts before i go to bed.)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

:-D hehe
Post Reply