すべての異なるタイプのリンク (相対、絶対、ルート相対) を含む html を含むテキストの文字列があります。preg_replace
他のリンクに触れることなく、すべての相対リンクをルート相対リンクに置き換えるためにPHP で実行できる正規表現が必要です。私はすでにルートパスを持っています。
置き換えられたリンク:
<tag ... href="path/to_file.ext" ... > ---> <tag ... href="/basepath/path/to_file.ext" ... >
<tag ... href="path/to_file.ext" ... /> ---> <tag ... href="/basepath/path/to_file.ext" ... />
手つかずのリンク:
<tag ... href="/any/path" ... >
<tag ... href="/any/path" ... />
<tag ... href="protocol://domain.com/any/path" ... >
<tag ... href="protocol://domain.com/any/path" ... />