当我将缩小的HTML输出到数据库中的文件时,它会对其进行优化

I am creating a few hundred files that are found in a database. $row['content'] is all highly minified html.

I have tried a few solutions to format the html that exist as a string but no solutions have worked too well for formatting minified html on a single line.

I also have rules set on how I format like format using spaces not tabs and 3 spaces per indent.

 $query =  "select page.page_id, page.title, page.content from cms_page page"
if ($result = $mysqli->query($query)) {    
     while($row = $result->fetch_assoc()) {
        file_put_contents($directory. $fileName, $row['content']);
       }
    }
}

You could try out the PHP class Dindent. I have tried it out once, and it seems to do what you are asking. It also has an option for the indentation character(s) you want to use, so your 3 spaces per indent should be possible.

To use the class with your current code:

$indenter = new \Gajus\Dindent\Indenter(array('indentation_character'=>'   '));
$query =  "select page.page_id, page.title, page.content from cms_page page";
if ($result = $mysqli->query($query)) {    
    while($row = $result->fetch_assoc()) {
        $indented = $indenter->indent($row['content']);
        file_put_contents($directory. $fileName, $indented);
    }
}