loadHTMLFile($file); // Suppress warnings for invalid HTML // Remove tags while (($baseTags = $doc->getElementsByTagName('base')) && $baseTags->length) { $baseTag = $baseTags->item(0); $baseTag->parentNode->removeChild($baseTag); } $links = $doc->getElementsByTagName('a'); foreach ($links as $link) { if ($link->hasAttribute('href')) { $href = $link->getAttribute('href'); // Replace and capitalize as needed $href = preg_replace_callback( '/(namespaces|classes|packages)\/([a-zA-Z])/', function ($matches) { // Capitalize the first letter after the prefix and replace / with - if ($matches[1] === 'classes') { $prefix = 'class'; // Directly set to 'class' for 'classes' } else { // For 'namespaces' and 'packages', simply remove the last character $prefix = substr($matches[1], 0, -1); } return $prefix . '-' . strtoupper($matches[2]); }, $href ); // Replace dashes with dots after the specific prefixes $href = preg_replace_callback( '/(namespace-|class-|package-)([\w-]+)\.html/', function ($matches) { // Replace all dashes in the suffix part with dots $suffix = str_replace("-", ".", $matches[2]); return $matches[1] . $suffix . '.html'; }, $href ); $link->setAttribute('href', $href); } } // Remove