jacko310592 Posted May 11, 2010 Share Posted May 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/ Share on other sites More sharing options...
Muddy_Funster Posted May 11, 2010 Share Posted May 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/#findComment-1056353 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/#findComment-1056391 Share on other sites More sharing options...
ignace Posted May 11, 2010 Share Posted May 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/#findComment-1056446 Share on other sites More sharing options...
Muddy_Funster Posted May 11, 2010 Share Posted May 11, 2010 ahhh....but you assume he has a development machine! Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/#findComment-1056470 Share on other sites More sharing options...
jacko310592 Posted May 11, 2010 Author Share Posted May 11, 2010 thanks for the replies everyone, i think ill have to go with ignace idea and just have the easy to read versions locally. thanks again eveyone Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/#findComment-1056473 Share on other sites More sharing options...
teamatomic Posted May 11, 2010 Share Posted May 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201348-echo-to-single-lines-on-ouput-while-indented-etc-within-the-text-editor/#findComment-1056481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.