Solved

outputting linebreaks in HTML comments

Posted on 2006-10-19
4
188 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
  • 2
  • 2
4 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 250 total points
Comment Utility
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
Comment Utility
figured it out.  points to me!
0
 

Author Comment

by:bakum
Comment Utility
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
Comment Utility
> 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now