I am working on a project where i need to parse and manipulate HTML. I have a requirement of replacing 'Base Url' in the HTML string. I am trying to use RegEx for the purpose. I have tried multiple patterns, but no luck. Below is my current code -
<?php
$html = '<html><head><base href="/" /></head><body></body></html>';
$base = 'https://SOME_URL/';
$output = preg_replace('/<base href="(.+)">/', $base, $html);
print $output;
Current Output -
$html = '<html><head><base href="/" /></head><body></body></html>';
Expected Output -
$html = '<html><head><base href="https://SOME_URL/" /></head><body></body></html>';