Page 1 of 1

Code line breaks

Posted: Mon May 03, 2010 9:40 am
by easinewe
When I output a list in php I always get the following format....

<li class="arrow"><a href="#210502">Adidas Sports Performance</a></li><li class="arrow"><a href="#200092">Aedes De Venustas</a></li><li class="arrow"><a href="#210111">African Paradise</a></li><li class="arrow"><a href="#210236">Agata & Valentina</a></li>

With all the code on one line. How can I force it to display like this in the code instead....

<li class="arrow"><a href="#210502">Adidas Sports Performance</a></li>
<li class="arrow"><a href="#200092">Aedes De Venustas</a></li>
<li class="arrow"><a href="#210111">African Paradise</a></li>
<li class="arrow"><a href="#210236">Agata & Valentina</a></li>

Is there something I can find and replace in the code after input to force a line break. A line break in the code only, obviously it will show on separate lines when viewed on the web.

Re: Code line breaks

Posted: Mon May 03, 2010 9:59 am
by rnoack
i'm not sure about the php code for this because i never did it before.
but it seems like you want the line breaks after </li>

if you already know how to do find/replace just search for "</li>" and replace with "</li><br>" or "</li>\n" or whatever you want to do...

Re: Code line breaks

Posted: Mon May 03, 2010 11:34 am
by AbraCadaver
You can put physical line breaks like:

Code: Select all

echo '<li class="arrow"><a href="#210502">Adidas Sports Performance</a></li>
<li class="arrow"><a href="#200092">Aedes De Venustas</a></li>';
Or you can add the newline character \n

Re: Code line breaks

Posted: Mon May 03, 2010 11:37 am
by hypedupdawg
Yes, I agree with AbraCadaver:

Code: Select all

<?php 
$i = 1;
while ($i < 5)
	{
	print "This is line " . $i . "<br/>

";
	$i++;
	}
?>
Will give you what you want. Any whitespace inside the string is saved in php. So the source code will look like this.

Code: Select all

<body>
<p>
This is line 1<br/>

This is line 2<br/>

This is line 3<br/>

This is line 4<br/>

</p>
</body>

Re: Code line breaks

Posted: Mon May 03, 2010 3:23 pm
by easinewe
Thanks I'll give those a try.