• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

outputting linebreaks in HTML comments

Hi, I've got some PHP code which strings together some HTML output based on some various factors.  My problem is the resulting code looks like one big solid block of text in the HTML comments.  I want it to be clean and neat with line breaks between the elements as if I coded directly to HTML.  Any clues how to do this?

thanks!
0
bakum
Asked:
bakum
  • 2
  • 2
1 Solution
 
b0lsc0ttCommented:
bakum,

As you write the PHP code insert \n where you want a line break to appear in the source.  For example ...

echo "<h1>This is a title</h1>\n";
echo "<p>A Paragraph</p>\n";

Depending on your server you may need to use \n\r which is for new line, carriage return.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
bakumAuthor Commented:
figured it out.  points to me!
0
 
bakumAuthor Commented:
sorry, meant points to you.  why did I write me?

Incidentally, you have to use " in your PHP code for them to work.  If you have say $myCode = '<a href="/index.php">home</a>\n'; that doesn't work for some reason.  but flip the quotes and it does.  That was about ten minutes of head bashing right there.
0
 
b0lsc0ttCommented:
> sorry, meant points to you.  why did I write me?
Yeah, that was a little confusing. :)

I'm glad that I could help you.  Strings in double quote marks are processed a little differently from those with single quotes.  The issue you found is similar to not being able to reference a variable in a string with single quotes but you can with double quotes.  For example ...

echo "Hi from $me";  //will work
echo 'Hi from $me';  //will not work
echo 'Hi from ' . $me;  //will work

I would normally write the line in your last comment like this ...

$myCode = "<a href=\"/index.php\">home</a>\n"; // the backslash (\) escapes the "

Thank you for the grade, the points and the fun question.  I'm glad that you are making the effort to make the html readable.  I believe it is worth it.

bol
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now