tags with href attribute for CSS files $pattern = '/]*?\srel=["\']?stylesheet["\'].*?\shref=["\']?\/(.*?)["\'][^>]*?>/i'; // Use preg_replace_callback to replace matched link tags with inline styles $outputString = preg_replace_callback($pattern, function($match) { // Extract the href attribute value $href = $match[1]; $cssFilePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $href; // Get the content of the local CSS file $cssContent = file_get_contents($cssFilePath); // Get the directory where the CSS file is located $cssDir = dirname($cssFilePath); // Replace relative paths in the CSS content to be relative to the CSS file's directory $cssContent = preg_replace_callback('/url\(["\']?(\/.*?|.*?)["\']?\)/i', function($urlMatch) use ($cssDir) { // Extract the URL value $url = $urlMatch[1]; // Combine with the CSS file's directory to create an absolute path $absolutePath = $cssDir . '/' . $url; // Make the path relative to the CSS file's directory $relativePath = ltrim(substr($absolutePath, strlen($_SERVER['DOCUMENT_ROOT'])), '/'); // Create the updated url() declaration $updatedUrlDeclaration = 'url("' . $relativePath . '")'; return $updatedUrlDeclaration; }, $cssContent); // Create an inline style tag with the modified CSS content return ""; }, $inputString); return $outputString; } function inlineScriptFromSrc($inputString) { // Define the regular expression pattern to match "; }, $inputString); return $outputString; }