Code line breaks

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
easinewe
Forum Newbie
Posts: 23
Joined: Mon Jan 11, 2010 3:22 pm

Code line breaks

Post 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.
rnoack
Forum Commoner
Posts: 34
Joined: Mon May 03, 2010 12:38 am

Re: Code line breaks

Post 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...
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Code line breaks

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
hypedupdawg
Forum Commoner
Posts: 74
Joined: Sat Apr 10, 2010 5:21 am

Re: Code line breaks

Post 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>
easinewe
Forum Newbie
Posts: 23
Joined: Mon Jan 11, 2010 3:22 pm

Re: Code line breaks

Post by easinewe »

Thanks I'll give those a try.
Post Reply