Solved

outputting linebreaks in HTML comments

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which userID to use for shopping cart application 13 27
What does != "" mean in programming 8 82
Email called spam 5 36
IP 10.0.1.2 / 255.0.0.0 61 56
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

827 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