phphtmlmarkdownfile-get-contentsparsedown

PHP file_get_contents not getting all content


I'm having a strange problem with the file_get_contents function of PHP, I'm currently creating an application which reads .md files. I have created a command which builds the .md files in a single html file which works perfectly. It puts all the html in the right files.

But if you are writing the .md file it's a pain to build the html to see what it looks like after every edit. So I created a php script which can be accessed by a browser and it'll do exactly the same as the command but instead of putting the html content in files it'll echo it out on your screen. But if you call this script it's not reading the entire file and it cuts off the last part of the html...

The .md File

### Test Readme for Category One

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam porttitor felis enim, molestie tincidunt erat feugiat a. 
Donec quis odio quis quam blandit convallis. Aenean eu lacus risus. Nulla congue non dui eu convallis. 

Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Integer ac ante laoreet, placerat diam in, 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam porttitor felis enim, molestie tincidunt erat feugiat a. 

Donec quis odio quis quam blandit convallis. Aenean eu lacus risus. Nulla congue non dui eu convallis. 
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Integer ac ante laoreet, placerat diam in, 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam porttitor felis enim, molestie tincidunt erat feugiat a.

Donec quis odio quis quam blandit convallis. Aenean eu lacus risus. Nulla congue non dui eu convallis.                                                                                                                                  
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Integer ac ante laoreet, placerat diam in, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam porttitor felis enim, molestie tincidunt erat feugiat a. 
Donec quis odio quis quam blandit convallis. Aenean eu lacus risus. Nulla congue non dui eu convallis. 

The output

<h3>Test Readme for Category One</h3>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam porttitor felis enim, molestie tincidunt erat feugiat a. 
Donec quis odio quis quam blandit convallis. Aenean eu lacus risus. Nulla congue non dui eu convallis.</p>

<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Integer ac ante laoreet, placerat diam in, 
Lorem ipsum dolor sit amet, consecte

As you can see it cuts part of the md file. I use this library to convert the md content to HTML https://github.com/erusev/parsedown-extra

Does anyone has a thought what it could be?

Thanks!

=== EDIT ===

I debugged it with this file: https://raw.githubusercontent.com/SeBuDesign/Write-Down/08be2a10281d99768f1d73ad7916b0bbc37903ea/docs/00_Category_One/00_Read_Me.md

Stored the contents of that file in a local file and perform a file_get_contents of that local file. It's the first file it processes, the following it the outcome:

### Test Readme Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam porttitor felis enim, molestie tincidunt erat feugiat a. Donec quis odio quis quam blandit convallis. Aenean eu lacus risus. Nulla congue non dui eu convallis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Integer ac ante laoreet, placerat diam in, hendrerit augue. Mauris pharetra, dui sed facilisis condimentum, ex lorem lobortis ante, ut ultrices nibh felis sit amet nibh. Pellentesque eget interdum nibh. Aenean interdum felis at tellus bibendum aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus velit augue, interdum id metus id, iaculis porttitor purus.

For the people who want to see the function that gets the content:

/**
     * Parses the md files of the given path
     *
     * @return string
     */
    public function parseItems()
    {
        $iterate = $this->getRecursiveIterator();

        $html = "";
        foreach ($iterate as $fullPath => $fileInfo) {
            /** @var $fileInfo SplFileInfo */

            // Check if it's a directory or a .md file
            if ($fileInfo->getExtension() == 'md') {

                $fileName = StringHelper::removeMdExtension(StringHelper::removeOrderChars($fileInfo->getFilename()));

                $id = "";
                for ($depth = $iterate->getDepth() - 1; $depth >= 0; $depth--) {
                    $id .= StringHelper::removeOrderChars($iterate->getSubIterator($depth)->current()->getFilename())."/";
                }
                $id .= $fileName;

                $headerName = str_replace("_", " ", $fileName);
                $html .= "<h1 id='{$id}'>{$headerName}</h1>";

                $mdContent = file_get_contents($fileInfo->getRealPath());
                print_r($mdContent);die();
                $parseDown = new ParsedownExtra();
                $html .= $parseDown->text($mdContent);
            }
        }

        return $html;
}

Solution

  • I put the code on my live server instead of my local dev machine and it works like a charm on my live machine... I compared the 2 PHP.ini's and nothing special points out that there is something misconfigured... So I'm going to reinstall my dev machine I guess :)

    Thanks for the help!