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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:44:40+00:00 2026-05-27T07:44:40+00:00

Below is the code I am using. It reads links from a textarea, and

  • 0

Below is the code I am using.

It reads links from a textarea, and then gets the source code and finally filters the meta tags. However it only displays the last element in the array.

So if for example I put 3 websites into the textarea, it will only read the last one, the others are just shown as blank.

Have spent hours trying this, please help.

function file_get_contents_curl($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

if(isset($_POST['url'])){
    $url = $_POST['url'];
    $url = explode("\n",$url);
    print_r($url);
    for($counter = 0; $counter < count($url); $counter++){
        $html = file_get_contents_curl($url[$counter]); // PASSING LAST VALUE OF ARRAY
        $doc = new DOMDocument();
        @$doc->loadHTML($html);
        $nodes = $doc->getElementsByTagName('title');
        $title = $nodes->item(0)->nodeValue;
        $metas = $doc->getElementsByTagName('meta');
        for ($i = 0; $i < $metas->length; $i++){
            $meta = $metas->item($i);
            if($meta->getAttribute('name') == 'description')
                $description = $meta->getAttribute('content');
            if($meta->getAttribute('name') == 'keywords')
                $keywords = $meta->getAttribute('content');
        }
        print
        ('
        <fieldset>
            <table>
                <legend><b>URL: </b>'.$url[$counter].'</legend>
                <tr>
                    <td><b>Title:</b></td><td>'.$title.'</td>
                </tr>
                <tr>
                    <td><b>Description:</b></td><td>'.$description.'</td>
                </tr>
                <tr>
                    <td><b>Keywords:</b></td><td>'.$keywords.'</td>
                </tr>
            </table>
        </fieldset><br />
        ');
    }
}                            
  • 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-27T07:44:41+00:00Added an answer on May 27, 2026 at 7:44 am

    This was an annoying little bug to find – but here is the (ridiculously simple) solution:

    Your URLs are getting white space added to them, for all but the last URL therefore you’ll need to trim it, you can do the following:

    curl_setopt($ch, CURLOPT_URL, trim($url));
    

    If available, you could have possibly just used file_get_contents() (still requires you trimming the URL).

    The second problem is that if there is no meta data then the old variables are used (from the previous loop) so just before the end of your main loop, after your print() add the following:

    unset($title,$description,$keywords);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the below code, using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection)) { while (dr.Read()) { _emailTemplate.EmailContent
I am using jquery datepicker, please see below code $(document).ready(function() { $(.txtDate).datepicker({ showOn: 'button',
i am using below code to change the the font type of text view.
I am using below code to create a reminder in Google calendar (using Google
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
I have the code below: using (SqlCommand command = new SqlCommand()) { command.CommandType =
I would like to implement a parallel version of the code below using threads
In past, I am using Listview and using below code can show a particular
I want to enable auto update script in flex3. i am using below code
I am actually having a list of text boxes. I am using below code

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.