Jump to content

echo to single lines on ouput while indented (etc) within the text editor


jacko310592

Recommended Posts

firstly, sorry for the rather poor title.

 

basically what im looking to do is echo out all my data on a single line within the page source code, but without removing indents, linebreaks etc from the html/php text editor (makig it hard for others to read the source, but easy when i need to edit my pages).

 

so within the page source, the html looks somthing like:

<div><span>blah blah</span></div>

 

rather than looking like:

<div>

<span>

blah blah

</span>

</div>

 

all i have so far is putting an 'echo' on each new line, is this the best way to do this?

<?php
echo "<div>";
echo "<span>";
echo "blah blah";
echo "</sapn>";
echo "</div>";
?>

 

hope i've explained myself well

thanks guys

Link to comment
Share on other sites

hmm...not somthing I have come accross before.  My best guess would be to store your code in a flat file (.txt for example), load it into a variable with FILE_GET_CONTENTS() and then use str_replace() to remove all formating before echong the code to the page.

 

This is a *relativly* high overhed for the server just  to produce a page however and there is probably a MUCH better way of doing it, but I just don't know what it is.

Link to comment
Share on other sites

you can always have dreamweaver re-format the code properly.

 

Look at it this way, do you want the generated code neat and tidy or would you rather pages load with as little server side effort as possible and keep your PHP code clean and tidy?

 

Anyone who is pulling your pages from generated source should be met with the discomfort of making it look clean.

Link to comment
Share on other sites

You are looking at it in the wrong way, everyone by the way. You keep your files on your development server (laptop, desktop) and before you upload it to your production server you would pass it through an obfuscater (or some other program that will remove everything like spaces, newlines and tabs) and put it in some temporary directory and start to upload it.

 

Your files with the nice newlines, spaces and tabs is kept on your development machine and all obfuscated code is put on the production server.

Link to comment
Share on other sites

Just dont add new lines (\n) or use <pre> and it should end up on one line.

<?php
echo "<div>";
echo "<span>";
echo "blah blah";
echo "</sapn>";
echo "</div>";
?>

This will show up in the source as

<div><span>blah blah</span><div>

 

 

HTH

Teamatomic

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.