\s*(.*?)\s*using filter : HTML \(StarCalc\)/'; // 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; } function update_src_paths($htmlPath, $newBasePath) { // Load HTML content from the file if(is_null($htmlPath)) { dd("htmlPath null dönüyor"); } $htmlContent = file_get_contents($htmlPath); // Create a new DOMDocument instance $dom = new DOMDocument(); // Suppress warnings due to malformed HTML libxml_use_internal_errors(true); // Load HTML into the DOMDocument $dom->loadHTML($htmlContent, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); // Restore error handling libxml_clear_errors(); // Get all 'src' attributes $xpath = new DOMXPath($dom); $srcAttributes = $xpath->query('//img/@src | //script/@src | //link/@href'); foreach ($srcAttributes as $attribute) { $currentValue = $attribute->value; // Extract the current path and replace it with the new base path $updatedValue = url($newBasePath) . "/" . $currentValue; $attribute->value = $updatedValue; } // Save the updated HTML back to the file $updatedHtmlContent = $dom->saveHTML(); chmod("storage/documents/", 0777); unlink($htmlPath); if (!file_exists(dirname($htmlPath))) { mkdir(dirname($htmlPath), 0777, true); } file_put_contents($htmlPath, $updatedHtmlContent); } ?>