Is using highlight_string() a recommended method for preserving PHP code formatting in Word?

Using `highlight_string()` is not a recommended method for preserving PHP code formatting in Word as it is primarily used for syntax highlighting in web pages. To preserve code formatting in Word, it is better to use a tool or plugin that can convert code to a format compatible with Word, such as converting it to a PDF or using a syntax highlighting plugin in Word.

// Example of converting PHP code to a PDF file for preserving formatting in Word
$code = "<?php echo 'Hello, World!'; ?>";

// Create a temporary file to store the PHP code
$tempFile = tempnam(sys_get_temp_dir(), 'php_code');
file_put_contents($tempFile, $code);

// Use a library like TCPDF to convert the code to a PDF file
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF();
$pdf->AddPage();
$pdf->SetFont('times', '', 12);
$pdf->writeHTML('<pre>' . htmlspecialchars($code) . '</pre>');
$pdf->Output('php_code.pdf', 'F');