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

  • SEARCH
  • Home
  • 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 7665259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:31:06+00:00 2026-05-31T14:31:06+00:00

How to get the contents of an href attribute on an HTML page, based

  • 0

How to get the contents of an href attribute on an HTML page, based on simple HTML DOM.
Here is an example of my script:

<?php
/* update your path accordingly */
include_once 'simple_html_dom.php';

$url = "http://www.codesphp.com/";
$html = file_get_html($url);
$ret =  $html->find('span.titleSnnipets');



foreach($ret as $story){
    echo $story->find('a',0).'<br/>';
}
?>

this script retrieve all tags on the page,i try to retrieve the contents of the attribute of all links.

  • 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-05-31T14:31:08+00:00Added an answer on May 31, 2026 at 2:31 pm

    Since we can’t see the content of your localhost, it is difficult to help you with. I only saw one small thing that I know could be optimized, and that is the first find() call.

    <?php
    include_once 'simple_html_dom.php';
    
    $url = "http://localhost/website/";
    $html = file_get_html($url);
    $ret =  $html->find('span.title');
    
    foreach($ret as $story)
    {
        echo $story->find('a',0).'<br/>';
    }
    ?>
    

    Update:
    I already said, since I can’t see the content you are using, it is difficult to help you. Your response is to just ask for help again, but make no effort to provide the content? Since you refuse to make your content accessible, I have rewritten your code to use google instead. This example works as expected. Take it and modify it as you need. Until you provide your content, I cannot help you any further.

    <?php
    include_once 'simple_html_dom.php';
    $html = file_get_html('http://www.google.com/');
    $divs = $html->find('div.gbm');
    foreach($divs as $element)
    {
        echo $element->find('a', 0).'<br>';
    }
    ?>
    

    Update #2: This will pull all of the links on the page and display them.

    <?php
    include_once 'simple_html_dom.php';
    $html = file_get_html('http://www.codesphp.com/');
    $links = $html->find('a');
    foreach($links as $link)
    {
        echo $link->href.'<br>';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After load content to page using div.load('page.php'); I need get all of links from
I am using Mechanize gem to parse html content. Firing this on terminal, agent.get(http://www.example.com/).search(.sidebar-deal-excerpt).first
Am using jquery and tabs based on http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/ <script type=text/javascript> $(function() { $(.tab_content).hide(); //Hide
I would like to get contents of some stream or project I can find
I'm using file_get_contents('mysourcefile.html') to load the contents of mysourcefile.html into mysql db. I have
$xml = file_get_contents(example.com); $dom = new DomDocument(); $dom->loadXML($xml); $items = $dom->documentElement; foreach($items->childNodes as $item)
I get a page using file_get_contents from a remote server, but I want to
With php file_get_contents() i want just only the post and image. But it's get
I'm trying to get the contents from another file with file_get_contents (don't ask why).
I'm using PHP's function file_get_contents() to fetch contents of a URL and then I

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.