function _absolute_url in Relative Path to Absolute URLs 6
Same name and namespace in other branches
- 7 rel_to_abs.module \_absolute_url()
Helper for filter processing.
Parameters
string $txt: String to process on.
string $base_url: Base Url string.
Return value
string Processed string of source text.
1 call to _absolute_url()
- rel_to_abs_filter in ./
rel_to_abs.module - Implementation of hook_filter().
File
- ./
rel_to_abs.module, line 62 - Relative Paths to Absolute URLs
Code
function _absolute_url($txt, $base_url) {
$needles = array(
'href="',
'src="',
'background="',
);
$new_txt = '';
if (substr($base_url, -1) != '/') {
$base_url .= '/';
}
$new_base_url = $base_url;
foreach ($needles as $needle) {
while ($pos = strpos($txt, $needle)) {
$pos += strlen($needle);
if (substr($txt, $pos, 7) != 'http://' && substr($txt, $pos, 8) != 'https://' && substr($txt, $pos, 6) != 'ftp://' && substr($txt, $pos, 7) != 'mailto:' && substr($txt, $pos, 2) != '//') {
$last = substr($txt, $pos, 1);
$new_txt .= substr($txt, 0, $pos) . ($last == '/' ? rtrim($new_base_url, '/') : $new_base_url);
}
else {
$new_txt .= substr($txt, 0, $pos);
}
$txt = substr($txt, $pos);
}
$txt = $new_txt . $txt;
$new_txt = '';
}
return $txt;
}