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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:36:44+00:00 2026-05-28T15:36:44+00:00

I am using curl to fetch website content into a variable. Now, using either

  • 0

I am using curl to fetch website content into a variable. Now, using either the ‘url’ or the fetched content i want to extract all the <p> tags into a variable.
Can anyone guide me on this ?

After hours i have just been able to create a DOM Document in php !

This is the code i have written:

$domDoc = new DOMDocument();
$domDoc->loadHTML($content);

print_r($domDoc);

$paragraphs = $domDoc->getElementsByTagName("p");
foreach ($paragraphs as $paragraph)
    $paragraph->item(0)->nodevalue;

where $content contains the website content fetched using

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url[url]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml_contents = curl_exec ($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
$website_content = $xml_contents;

Can someone please guide me ?

  • 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-28T15:36:45+00:00Added an answer on May 28, 2026 at 3:36 pm

    You don’t need to use item() in the foreach loop. Simply access nodeValue directly from the $paragraph variable to get the content of the p tag.

    You’ll want to use item() only if you’re using a normal for loop.

    for ($i = 0; $i < $paragraphs->length; $i++) 
    {
        echo $paragraphs->item($i)->nodeValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHP cURL to fetch information from another website and insert it into
I'm using CURL to extract some real estate listings. But, recently, a website changed
I am using PHP cURL to fetch XML output from a URL. Here is
I'm using curl to fetch data from many website. Sometimes they send back gzip.
Im using curl through php to fetch a url. I am successfully able to
Im using curl to fetch my Twitter favorites: <?php $username = bob; $password =
I'm using CURL to fetch some data from user accounts. First it logs in
I'm trying to fetch the contents of a page using CURL. The page that
I'm using curl to make php send an http request to some website somewhere
I have to fetch content of some urls by using proxies from a list.

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.