[TYPO3-english] typolink and absolute URL

Stephan Petzl spetzl at gmx.at
Wed Jan 28 14:44:09 CET 2009


Jan Bednarik schrieb:
> Hi,
> 
>> i m writing a newsletter extension at the moment and therefor i have 
>> to generate absolute links in texts.
>> is there a typoscript way of defining that i want to have some links 
>> with absolute urls?
>> i think there should be a typolink property for this!
> 
> if it's an extension and you generate links in your PHP code, then you 
> could use t3lib_div::locationHeaderUrl($URL)
> 
> Regards
> 
not exactly what i needed. found a good solution here:
http://blog.verkoyen.eu/2007/04/04/convert-relative-urls-into-absolute/

some little changes, and works now perfectly

/**
   * Convert from relative urls to absolute urls
   *
   * @param    string    $prefix
   * @param    string    $html
   * @return    string
   */
   function relativeToAbsolute($prefix, $html)
   {
     // search for single quotes and replace them by double quotes
     $search = '\'';
     $replace = '"';
     $html = str_replace($search, $replace, $html);
     // replace relative urls by absolute (prefix them with $prefix)
     $pattern = '/href="(?!http|https|ftp|irc|feed|mailto)([\/]?)(.*)"/i';
     $replace = 'href="'.$prefix.'/$2"';
     $html = preg_replace($pattern, $replace, $html);

     $pattern = '/src="(?!http|https|ftp|irc|feed|mailto)([\/]?)(.*)"/i';
     $replace = 'src="'.$prefix.'/$2"';
     $html = preg_replace($pattern, $replace, $html);
     // return
     return $html;
   }

BR Steph


More information about the TYPO3-english mailing list