note 74389 deleted from function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Wed, 11 Apr 2007 11:48:51 +0000 |
| Subject: | note 74389 deleted from function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125287@lists.php.net to get a copy of this message | ||
Note Submitter: bennyhur at gmail [dot] com
----
Use this function to convert relative links in a block of HTML
to absolute links which point to the specified absolute root:
<?php
function relative2absolute($html, $absolute_root, $doCss=false)
{ //SEE: http://wintermute.com.au/bits/2005-09/php-relative-absolute-links/
$str =
preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\s|\+)[^"]*"))#',
'$1="' . $absolute_root . '/$2$3', $html);
if($doCss)
$str = str_replace('@import url("/',
'@import url("' . $absolute_root . '/', $str);
return $str;
}
?>