I\'m using cURL to pull the contents of a remote site. I need to check all \"href=\" attributes and determine if they\'re relative or absolute path, then get the value of the li
Here is the one possible solution if i understood question correctly:
$prefix = 'http://www.website.com/index.php?url=';
$regex = '~()~is';
$html = file_get_contents('http://cnn.com');
$html = preg_replace_callback($regex, function($input) use ($prefix) {
$parsed = parse_url($input[2]);
if (is_array($parsed) && sizeof($parsed) == 1 && isset($parsed['path'])) {
return $input[1] . $prefix . $parsed['path'] . $input[3];
}
}, $html);
echo $html;