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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:45:04+00:00 2026-05-20T17:45:04+00:00

This question may be a bit specific for stackoverflow, but here it is. I

  • 0

This question may be a bit specific for stackoverflow, but here it is. I have a php file that is taking html, writing it to a new file, inserting the file name into a database…all that works fine.

Now I want to extract the links in the html, using DOM. I got code from here and get the following error:

Parse error: syntax error, unexpected $end … on line 72

It would seem that I forgot to close something or closed something unsuspectingly. However the only new code is from the above link and it appears to be in order. However I am new to DOM and PHP, so perhaps you can help. Any pointers are appreciated. Here is what I have added:

$dom = new DOMDocument();
@$dom->loadHTML($curl_scraped_page);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

//the above works fine, but when I add the loop bellow it fails


for ($i = 0; $i < $hrefs->length; $i++) {
    $href = $hrefs->item($i);
    $url = $href->getAttribute('href');
    storeLink($url,$target_url);

function storeLink($url) {
    $query = "INSERT INTO happyturtle (ad2, ad3) VALUES ('$url', '$gathered_from')";
    mysql_query($query) or die('Error, insert query failed');

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
}

For the sake of completeness, here is the whole code with the new bits included:

<html>
<body>

<?
$urls=explode("\n", $_POST['url']);
$proxies=explode("\n", $_POST['proxy']);

for ( $counter = 0; $counter <= 6; $counter++) {
for ( $count = 0; $count <= 6; $count++) {

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$urls[$counter]);
 curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
 curl_setopt($ch, CURLOPT_PROXY,$proxies[$count]);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'GET');
 curl_setopt ($ch, CURLOPT_HEADER, 1); 
curl_exec ($ch); 
$curl_scraped_page = curl_exec($ch); 

$FileName = rand(0,100000000000);
$FileHandle = fopen($FileName, 'w') or die("can't open file");
fwrite($FileHandle, $curl_scraped_page);


$dom = new DOMDocument();
@$dom->loadHTML($curl_scraped_page);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

$hostname="****";
$username="****";
$password="****";
$dbname="****";
$usertable="****";

$con=mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname ,$con);


for ($i = 0; $i < $hrefs->length; $i++) {
    $href = $hrefs->item($i);
    $url = $href->getAttribute('href');
    storeLink($url,$target_url);

function storeLink($url) {
    $query = "INSERT INTO happyturtle (ad2, ad3) VALUES ('$url', '$gathered_from')";
    mysql_query($query) or die('Error, insert query failed');
$sql="INSERT INTO happyturtle (time, ad1)
VALUES
('$FileName','$domains')";

}

mysql_close($con);

fclose($FileHandle);

curl_close($ch);

echo $FileName; 

echo "<br/>";

}
}

?>

</body>
</html>
  • 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-20T17:45:05+00:00Added an answer on May 20, 2026 at 5:45 pm

    Try indenting your code properly.

    You’ll then see that the following for loop :

    for ( $counter = 0; $counter <= 6; $counter++) {
    

    is not closed : there is no ending } that correspond to its opening {

    (Well, actually, the message indicates there is a missing } somewhere, and this is shown when indenting the code — it might be this for-loop that’s not closed, or one of your other { ; up to you to find out what should be closed, depending on your code’s logic)

    Or maybe the problem is that you have two for loops that looks kind of the same :

    for ( $counter = 0; $counter <= 6; $counter++) {
        for ( $count = 0; $count <= 6; $count++) {
    
            // Some code
    
        } // closing of the inner for-loop
    // Here, the first for-loop is not closed
    

    So, either :

    • close the outer for-loop,
    • or remove it, if it’s not useful.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This may be a bit of a nooby question, I have been trying to
You may think this question is like this question asked on StackOverflow earlier. But
I concede that this question may fall into the 'discussable' but not 'answerable' category.
This question may be too product specifc but I'd like to know if anyone
This question may sound fairly elementary, but this is a debate I had with
Alright, I am going to state up front that this question may be too
There may be more than one way to ask this question, so here's a
this may be a naive question, but, as asked in the object, what is
I'm a bit scared to ask this question as it may start a religous

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.