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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:55:44+00:00 2026-05-24T16:55:44+00:00

i need to get only image that in current node and not in child

  • 0

i need to get only image that in current node and not in child nodes
i want to get only green/yellow/red/black images without not_important.gif image
i can use query './/table/tr/td/img'
but i need it inside loop

<?php
    /////////////////////////////////////////////////////////////////////
        $html='
            <table>
                <tr>
                    <td colspan="2">
                        <span>
                            <img src="not_important.gif" />
                        </span>
                        <img src="green.gif" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>yellow</span>
                        <img src="yellow.gif" />
                    </td>
                    <td>
                        <span>red</span>
                        <img src="red.gif" />
                    </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td>
                        <span>
                            <img src="not_important.gif" />
                        </span>
                        <img src="black.gif" />
                    </td>
                </tr>
            </table>
        ';
    /////////////////////////////////////////////////////////////////////
        $dom = new DOMDocument();
        $dom->loadHTML($html);
        $xpath = new DomXPath($dom);
    /////////////////////////////////////////////////////////////////////
        $query = $xpath->query('.//table/tr/td');
        for( $x=0,$results=''; $x<$query->length; $x++ )
        {
            $x1=$x+1;

            $image = $query->item($x)->getELementsByTagName('img')->item(0)->getAttribute('src');

            $results .= "image $x1 is : $image<br/>";
        }
        echo $results;
    /////////////////////////////////////////////////////////////////////
?>

can i do it through $query->item()->
i tried has_attributes and getElementsByTagNameNS and getElementById
but i failed ::

  • 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-24T16:55:46+00:00Added an answer on May 24, 2026 at 4:55 pm

    Replace:

    $image = $query->item($x)->getELementsByTagName('img')->item(0)->getAttribute('src');
    

    …with:

    $td = $query->item($x); // grab the td element
    $img = $xpath->query('./img',$td)->item(0); // grab the first direct img child element
    $image = $img->getAttribute('src'); // grab the source of the image
    

    In other words, use the XPath object again to query, but now for ./img, relative to the context node you provide as the second argument to query(). The context node being one of the elements (td) of the earlier result.

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

Sidebar

Related Questions

I need to get only 1 record from sql result. we use SELECT TOP
i have text like this div bla-bla end div i need to get only
I have a table with 11 columns, but I need to get only 2
I want to remove rectangles etc that enclose text in a screenshot image, so
Basically, I want to have an app with only one view that has an
I need to get the contents of a page (which is just an image)
Basically what the title says... I need to have an image that when clicked,
I have $(elements[current]).html(); that returns <a href=#><img style=width:991px;height:230px; src=img/image.jpg alt=img></a> and i need to
I have a simple black and white only gif image (400x400px let's say). I
I have an image that need to be removed, but I can't have access

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.