The Little Guy Posted September 20, 2008 Share Posted September 20, 2008 I would like to convert all links to "Exact" links, so for example, I want /dir/page.html -> http://somesite.com/dir/page.html dir/page.html -> http://somesite.com/dir/page.html http://somesite.com/dir/page/html -> http://somesite.com/dir/page/html $file_contents = preg_replace('~<a(.+?)href="(.+?)"~','<a$1href="http://dudeel.com/lProxy?p='.str_replace('//','/',$url.'/$2"'),$file_contents); I want the new URL to look like this: http://dudeel.com/lProxy?p=http://somesite.com/dir/page.html does all that make sense? Link to comment https://forums.phpfreaks.com/topic/125037-convert-absoluterealative-urls-to-exact-url/ Share on other sites More sharing options...
effigy Posted September 22, 2008 Share Posted September 22, 2008 See if this works for your data set: <pre> <?php $data = <<<DATA <a href="/dir/page.html">A</a> -> http://somesite.com/dir/page.html <a href="dir/page.html">B</a> -> http://somesite.com/dir/page.html <a href="http://somesite.com/dir/page/html">C</a> -> http://somesite.com/dir/page/html DATA; echo htmlspecialchars( preg_replace( '%(<a[^>]+)href="(?:http://[^/]+/|/)?([^"]+)"%', '$1href="http://dudeel.com/lProxy?p=http://somesite.com/$2', $data ) ); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/125037-convert-absoluterealative-urls-to-exact-url/#findComment-647700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.