Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:00:37+00:00 2026-06-11T00:00:37+00:00

i have a script which will fetch content from a website, what i wanna

  • 0

i have a script which will fetch content from a website, what i wanna do is modify all that links. Suppose:

$html = str_get_html('<h2 class="r"><a class="l" href="http://www.example.com/2009/07/page.html" onmousedown="return curwt(this, 'http://www.example.com/2009/07/page.html')">SEO Result Boost <b> </b></a></h2>');

so, is it possible to modify or rewrite it in this way>

<h2 class="r"><a class="l" href="http://www.site.com?http://www.example.com/2009/07/page.html">SEO Result Boost <b> </b></a></h2>

I have read it’s manual but can not understand how to figure it ( http://simplehtmldom.sourceforge.net/#fragment-12 )

Is It Possible, Any Idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:00:39+00:00Added an answer on June 11, 2026 at 12:00 am

    Assuming the answer to a related question works,

    You should be able to use the following working with Simple HTML DOM

    $site = "http://siteyourgettinglinksfrom.com";
    $doc = str_get_html($code);
    foreach ($doc->find('a[href]') as $a) {
    $href = $a->href;
    if (/* $href begins with a absolute URL path */) {
        $a->href = 'http://www.site.com?'.$href;
    }
    else{ /* $href begins with a relative path */        
        $a->href = 'http://www.site.com?'.$site.$href;
    }
    
    }
    $code = (string) $doc;
    

    or

    Using PHP’s native DOM library:

    $site = "http://siteyourgettinglinksfrom.com";
    $doc = new DOMDocument();
    $doc->loadHTML($code);
    $xpath = new DOMXpath($doc);
    foreach ($xpath->query('//a[@href]') as $a) {
    $href = $a->getAttribute('href');
    if (/* $href begins with a absolute URL path */) {
        $a->setAttribute('href', 'http://www.site.com?'.$href);
    }
    else{ /* $href begins with a relative path */
        $a->setAttribute('href', 'http://www.site.com?'.$site.$href);
    }
    }
    $code = $doc->saveHTML();
    

    Checking the $href:

    you would be checking for a relative link and prepend the address of the site your pulling the content from, since most sites use relative links. (this is where a regular expression matcher would be your best friend)

    for relative links you prepend the absoute path to the site which you are getting links from

      'http://www.site.com?'.$site.$href
    

    for absolute links you just append the relative link

      'http://www.site.com?'.$href
    

    Example links:

    site relative: /images/picture.jpg

    document relative: ../images/picture.jpg

    absolute: http://somesite.com/images/picture.jpg

    (Note: there is a little more work that needs done here, because if your handling “document relative” links, then you will have to know what directory you’re currently in. Site relative links should be good to go, as long as you have the root folder of the site you’re getting links from)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have PHP scrapping script which fetches HTML table content from another website. The
I have this script that displays all the users images which i will display
I have a script which will list all the files from the image folder
I currently have a script which will pull in image contents from a database
I'm writing a php script that will fetch data from a given URL and
I have partially developed a property website that fetch properties data from a RETS
I am working on a script which will fetch the latest tweets from the
I have a Perl script which will allow for a file to be uploaded
I have the following script which will delete a file off a BlackBerry. However,
I have a sed script which will read in a file and, if a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.