cross domain - PHP's file_get_contents: dealing with relative paths inside the result -


i'm trying solve cross-domain issue, i'm implementing script url parameter , open file_get_contents. works fine until page try relative paths (the following line inside index.html):

<script src="js/custom_script.js" /> 

if create regex preg_replace replace html data switching js/custom.js http://content.domain/js/custom_script.js works, problem don't know how many levels inside page i'm trying open, like: index.html have button page relative paths.

is there elegant solution problem?

i use base html tag, , instead of scraping through whole source, insert right before </head> tag.

could simple line of code: echo str_replace("</head>", "<base href=\"http://content.domain/\" target=\"_blank\"></head>", $source)

using base tag makes browser handle nested links you:

specify default url , default target links on page:


Comments