The title says it all. So, if you were to use this library on a website like http://example.com/test/testing/, you would get results like these:
-
- Before: http://example.com/test/another-test/#anchor
- After: ../another-test/#anchor
-
- Before: http://example.com/wp-content/themes/twentyten/style.css
- After: /wp-content/themes/twentyten/style.css
-
- Before: https://example.com/wp-content/themes/twentyten/style.css
- After: https://example.com/wp-content/themes/twentyten/style.css
-
- Before: http://google.com/test/
- After: //google.com/test/
-
- Before: ../../../../../../../../#anchor
- After: /#anchor
- After (
$output_type=1
): ../../#anchor
All string parsing. No directory browsing.
<?php
echo absolute_to_relative_url('http://your-domain.com/dir/');
?>
or
<?php
$instance = new Absolute_to_Relative_URLs('http://remote-site.com/');
echo $instance->relate_url('http://remote-site.com/dir/', false, 0);
?>