Hi I’m trying to read a PHP file. The complete contents of which needs to be assigned to a variable. The problem is when PHP reads the contents of the file it’s missing about 100 (one hundred) of the lines. The problem is the starting PHP tag on line 1:

<?php

When this is removed file_get_contents() works fine and all of the lines are returned. Does anyone know how to get over this?

Here is the code i'm running:

$contents = file_get_contents('exampleFile.php');
print $contents;

I have omitted ‘exampleFile.php’ as it is 150 lines long but I can paste it in if required?

Thanks
Jon

    should work fine, did you view source? The browser is probably not displaying it.

      I think Dagon is right: the content between <?php and ?> will be treated as a (invalid) HTML tag. For a quick sanity check, you could do:

      $contents = file_get_contents('exampleFile.php');
      printf("<pre>%s</pre>", htmlspecialchars($contents));
      

      That should show you everything that was obtained by the file_get_contents().

        Resolved. It was as you said; the HTML not outputting the start because of the < tag.

        Thanks

          Write a Reply...