Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-10-2012, 09:06 PM   PM User | #1
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
File contents - honour spaces

I have saved my JS file as a text file. I use four spaces for the indenting and if I open the file in a text editor these spaces are intact. But when I use file_get_contents() print_r confirms that often these spaces are doubled-up to eight.

Has anyone encountered this and know of a solution? Here's my code for reference:

PHP Code:
if (file_exists('includes/AndyG_js.txt')) {
    
$mylib file_get_contents('includes/AndyG_js.txt');
} else {
    
$mylib 'File not found, unfortunately! Contact the administrator of this site.';
}
print_r($mylib);

echo <<< THECODE
<pre class="prettyprint"><code class="language-javascript">{$mylib}
}</code></pre>
THECODE; 
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-10-2012, 09:21 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Scrub this question, sorry - they were tabs, not spaces

However, it's a fairly large file - 1000 lines. What code would you use to load this in stages, or would you use something other than file_get_contents()?
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 08-10-2012, 10:23 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Loading in stages doesn't make any sense. If its a JS file, it would need it in its entirety to make any sense of it (assuming the JS needs the entire thing).
You can however read it in stages. Use fopen/fread/fclose instead.
Fou-Lu is offline   Reply With Quote
Old 08-10-2012, 10:35 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Thank you @Fou-Lu

I'm not using the JS itself, I'm outputting the text content (of the JS file) using Google's Prettify.

Actually, 1000 lines isn't that long. I suspect it's the prettify-ing that's slowing it down. I should try and create a simple timer..

Perhaps I could read the file length and get the contents and prettify it in two or three stages, still using get_file_contents. Maybe I could read just 1/10th of the file first and prettify it, so at least there's some content displaying whilst the rest is being parsed.

But I'm open to suggestions
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:17 PM.


Advertisement
Log in to turn off these ads.