Files
citrus-cms/app/Functions/docx_to_html.php
T
2026-04-28 21:14:25 +03:00

36 lines
1.0 KiB
PHP

<?php
function docx_to_html($docx, $html_dir) {
// Ensure the LANG environment variable is set
putenv('LANG=ru_RU.UTF-8');
// Ensure the output directory exists
if (!is_dir($html_dir)) {
mkdir($html_dir, 0777, true);
}
// Construct the command
$command = "libreoffice --headless --convert-to html --outdir " . escapeshellarg($html_dir) . " " . escapeshellarg($docx);
// Execute the command
$output = shell_exec($command);
$output = extract_between_markers_docx($output);
update_src_paths($output, $html_dir);
return $output;
}
function extract_between_markers_docx($input_str) {
// Define the regular expression pattern to match the content between the markers
$pattern = '/->\s*(.*?)\s*using filter : HTML \(StarWriter\)/';
// Perform the regex match
if (preg_match($pattern, $input_str, $matches)) {
// Return the matched content
return $matches[1];
}
// Return null if no match is found
return null;
}
?>