1
<base href="http://www.w3schools.com/" target="_blank">

How can i add the above base URL for the particular div section using php like

If i have two div section

This section links will work with above base URl link

<div>
<a href="/help">help</a>
</div>

This section links will work with websites URl link

<div>
<a href="/help">help</a>
</div>

I'm trying "simple html dom" to fetch some content from some other website paste it under one div section that has relative links. That can be converted to direct link like "/images/image.png" to "www.example.com/images/image.png"

  • please post your desired output.your question is unclear. – R R Dec 18 '13 at 09:23
  • There is no such concept in html. You either have to code URLs instead of relative links or you have to alter the references dynamically using javascript. – arkascha Dec 18 '13 at 09:25

2 Answers2

1

There is no way to do this directly with html. You can do it with some server side languages like PHP like following.

<a href="<?php echo $base_url; ?>">abc</a>
<a href="<?php echo $current_url; ?>">abc</a>

or

You can also do it with javascript ( client side )

Sriraman
  • 7,658
  • 4
  • 40
  • 60
  • I'm trying "simple html dom" to fetch some content from some other website paste it under one div section that has relative links. That can be converted to direct link like "/images/image.png" to "www.example.com/images/image.png" – user3114504 Dec 18 '13 at 09:31
1
<div class='normalUrl'>
    <a href="/help">Help</a>
</div>

<div class='otherBaseUrl'>
    <a href="<?php print('http://some.otherwebsite.com'); ?>/help">Help</a>
</div>

This is a hardcoded way just to show how the end result can be achieved. I'm sure you want to make this more generic to fit your goal.

Viridis
  • 242
  • 1
  • 10
  • I'm trying "simple html dom" to fetch some content from some other website paste it under one div section that has relative links. That can be converted to direct link like "/images/image.png" to "www.example.com/images/image.png" – user3114504 Dec 18 '13 at 09:33
  • you already know what page you are on, considering you made the request to 'download' that page to parse it. You give your returned HTML to another function `correct_urls($html, $baseurl);`. Just set your `$baseurl` to the link you initially cURL'd, and you're good to go. -- This, assuming that you are doing all of this before rendering the page (PHP), and not with JS/jQuery. – Viridis Dec 18 '13 at 09:35