Reply to Re: Func to Turn Relative URLs into Abs URLs

Your name:

Reply:


Posted by tom on 10/08/82 11:34

FYI, by accident I just found a function that's pretty much what I was
looking for.

It's from the GREAT PHP web browser simulation class 'Snoopy', which
I've been using for ages now with great results:
http://sourceforge.net/projects/snoopy/

In case this thread is ever helpful to someone else, here's the
function _expandlinks from Snoopy:

/*======================================================================*\
Function: _expandlinks
Purpose: expand each link into a fully qualified URL
Input: $links the links to qualify
$URI the full URI to get the base from
Output: $expandedLinks the expanded links
\*======================================================================*/

function _expandlinks($links,$URI)
{

preg_match("/^[^\?]+/",$URI,$match);

$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
$match = preg_replace("|/$|","",$match);
$match_part = parse_url($match);
$match_root =
$match_part["scheme"]."://".$match_part["host"];

$search = array( "|^http://".preg_quote($this->host)."|i",
"|^(\/)|i",
"|^(?!http://)(?!mailto:)|i",
"|/\./|",
"|/[^\/]+/\.\./|"
);

$replace = array( "",
$match_root."/",
$match."/",
"/",
"/"
);

$expandedLinks = preg_replace($search,$replace,$links);

return $expandedLinks;
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация