tags with href attribute for CSS files $pattern = '//i'; // Use preg_replace_callback to replace matched link tags with inline styles $outputString = preg_replace_callback($pattern, function($match) use ($basePath) { // Extract the href attribute value $href = $match[1]; // Get the content of the local CSS file $cssContent = file_get_contents($basePath . '/assets/' . $href); // Create an inline style tag with the CSS content return ""; }, $inputString); return $outputString; } function inlineScriptFromSrc($inputString) { $basePath = '/path/to/your/local/files'; // Hardcoded base path // Define the regular expression pattern to match "; }, $inputString); return $outputString; }