Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts

    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

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •