Solved

outputting linebreaks in HTML comments

Posted on 2006-10-19
4
231 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 250 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

726 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