QA.TechInterviews.com - your tech questions answered
PHP: Is There A Way To Add Space In The Output File?
How do I give additional line breaks and spacing in a PHP output file. When PHP output a HTML file with echoes, it looks terrible without line breaks (although it looks fine on browser, but I find it terribly confusing to verify the generated code without the line breaks, and I'm also a neat person)

Note: if you're saying, add <br /> just get out from here, that's not what I'm asking.
what I mean:

PHP input File is like:
----
<?php whatever whatever ?>
----

*PHP Output File* is like:
----
<html>
the things here is generated by PHP
</html>
----

and Browser Viewed:
----
THIS TEXT IS BOLD (just imagine the all caps is bolded, since we can't use formatting in YA)
----

I think Garfieldswingsquisshy (forgive me if it's mistyped) has given the correct answer, thanks gar, I'll choose the best answer to you as soon as I'm online next time, and the 4 hour wait period finished.

Additional question: How about tabbing?
sheeple_rancher also gives a good explanation, geez I wish I could give the points to more than one good answerers.
sheeple_rancher also gives a good explanation thanks, geez I wish I could give the points to more than one good answerers.
I think the question is somewhat confusing because you mention a PHP output file.

It sounds like you want to view the code that you are writing a little easier by adding breaks. (assuming you know you can just add breaks it won't matter; therefore I'm missing what you mean by output file)

it sounds like the view in the browser - which you specified that's not what you are talking about. Becauser you are not intereseted in the <br /> tag - i'm also gathering the <p /> is also undesirable

If you wouldn't mind further elaboration so I know what is needed in your answer that'd be great.
echo ("\r\n");

Hey... thanks...

yeah, like he said, it has to be in double quotes... put it anywhere in the echo'd code that you want PHP to generate a carriage return.

\r is carriage return
\n is new line

Sometimes, depending on "whatever I dont know", a \r will work, sometimes a \n will work, sometimes you need both \r\n

As for your tabbing???
I think that is \t but Im not sure
What happens when you use <p> ?
I know exactly what you want.

print '<p>Here is line 1</p>' . "\n";
print '<p>Here is line 2</p>' . "\n";
print "<p>Here is \nline 3</p>" . "\n";

shows up as:

<p>Here is line 1</p>
<p>Here is line 2</p>
<p>Here is
line 3</p>

Note that \n is a newlinie and for it to be interpreted in a string rather than just output as the two charactrs, you have to enclose it in double quotes (look closely at line 3).

Adding the "\n" at the end (or wherever) will break up the raw html. You can turn the "\n" into a macro like EOL to make typing it easier.
also:

echo "my first line<BR>
";
echo "my second line<BR>
";

Back to QA. TechInterviews.com. Powered by Yahoo! Answers and TechInterviews.com community.