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? Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.