?
Solved

outputting linebreaks in HTML comments

Posted on 2006-10-19
4
Medium Priority
?
235 Views
Last Modified: 2006-11-18
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
Comment
Question by:bakum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 1000 total points
ID: 17770473
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
 

Author Comment

by:bakum
ID: 17770504
figured it out.  points to me!
0
 

Author Comment

by:bakum
ID: 17770512
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
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17770548
> 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

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question