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 6557055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:01:34+00:00 2026-05-25T13:01:34+00:00

I am trying to read all links with in a given url. here is

  • 0

I am trying to read all links with in a given url.

here is code I am using :

$dom = new DomDocument();
@$dom->loadHTMLFile($url);
$urls = $dom->getElementsByTagName('a');

foreach ($urls as $url) {
        echo $url->innertext ." => ".$url->getAttribute('href');

Script giving all links of given url.

But problem here is I am not able to get image links (image inside anchor tag)

First I tried with

$url->nodeValue

But it was giving anchor text having text values only.

I want to read both images and text links.
I want output in below formmat.

Input :

<a href="link1.php">first link</a>
<a href="link2.php"> <img src="imageone.jpg"></a>

Current Output:

first link => link1.php
=>link2.php with warning (Undefined property: DOMElement::$innertext )

Required Output :

first link => link1.php
<img src="imageone.jpg">=>link2.php 
  • 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-25T13:01:34+00:00Added an answer on May 25, 2026 at 1:01 pm

    innerText doesn’t exist in PHP; it’s a non-standard, Javascript extension to the DOM.

    I think what you want is effectively an innerHTML property. There isn’t a native way of achieving this. You can use the saveXML or, from PHP 5.3.6, saveHTML methods to export the HTML of each of the child nodes:

    function innerHTML($node) {
        $ret = '';
        foreach ($node->childNodes as $node) {
            $ret .= $node->ownerDocument->saveHTML($node);
        }
        return $ret;
    }
    

    Note that you’ll need to use saveXML before PHP 5.3.6

    You could then call it as so:

    echo innerHTML($url) ." => ".$url->getAttribute('href');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a text file, i'm using fileImputStream, and reading all the
I'm trying to read all the files in a folder. If the name is
I am trying to setup a central repository with shared hosting. I read all
I'm trying to build a small webmail app. When I read all the emails
I'm trying to read the event log for a security audit for all users
Trying to read an RSS and select information using Linq but can't seem to
I am trying to read information off of a smartcard, using a contact-less OmniKey
I'm trying to use jQuery to find all links on a page, then when
I'm trying to read a pdf file and get all hyperlinks from this file.
I am new to rails and using version 3.1.0 and trying to deploy to

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.