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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:20:08+00:00 2026-05-19T02:20:08+00:00

for some reason I get this error below when trying to use multiple require()

  • 0

for some reason I get this error below when trying to use multiple require() functions in my PHP. Basically, I’m use a couple require() functions to access a couple xml parser pages.
Does anyone know how to fix this?If this isn’t very descriptive please say below and I will try to fix it. Thank you. I appreciate any positive feedback. Also, I’m just learning PHP so please don’t be too harsh on me. I’m going to provide the following code below.

Here is the error:
Fatal error: Cannot redeclare startElement() (previously declared in /Applications/XAMPP/xamppfiles/htdocs/yournewsflow/news/sports.php:27) in /Applications/XAMPP/xamppfiles/htdocs/yournewsflow/news/political.php on line 34

Here are the require functions: 

        <?php

        require("news/sports.php");
        require("news/political.php");
        ?>




Here is the xml parser used for a couple pages:
<?php
$tag = "";
$title = "";
$description = "";
$link = "";
$pubDate = "";
$show= 50;
$feedzero = "http://feeds.finance.yahoo.com/rss/2.0/category-stocks?region=US&lang=en-US"; $feedone = "http://feeds.finance.yahoo.com/rss/2.0/category-ideas-and-strategies?region=US&lang=en-US"; 
$feedtwo  = "http://feeds.finance.yahoo.com/rss/2.0/category-earnings?region=US&lang=en-US"; $feedthree = "http://feeds.finance.yahoo.com/rss/2.0/category-bonds?region=US&lang=en-US";
$feedfour  = "http://feeds.finance.yahoo.com/rss/2.0/category-economy-govt-and-policy?region=US&lang=en-US";

$insideitem = false;
$counter = 0;
$outerData;

function startElement($parser, $name, $attrs) {
    global $insideitem, $tag, $title, $description, $link, $pubDate;
    if ($insideitem) {
        $tag = $name;
    } elseif ($name == "ITEM") {
        $insideitem = true;
    } }
function endElement($parser, $name) {
    global $insideitem, $tag, $counter, $show, $showHTML, $outerData;
    global $title, $description, $link, $pubDate;
    if ($name == "ITEM" && $counter < $show) {
        echo "<table>
                <tr>
                  <td>

        <a href=\"".htmlspecialchars($description)."\">".htmlspecialchars($description)."</a>
                  </td>
                </tr>";


        // if you chose to show the HTML
        if ($showHTML) {
            $title = htmlspecialchars($title);
            $description = htmlspecialchars($description);
            $link = htmlspecialchars($link);
            $pubDate = htmlspecialchars($pubDate);

        // if you chose not to show the HTML
        } else {
            $title = strip_tags($title);
            $description = strip_tags($description);
            $link = strip_tags($link);
            $pubDate = strip_tags($pubDate);
        }

        // fill the innerData array
        $innerData["title"] = $title;
        $innerData["description"] = $description;
        $innerData["link"] = $link;
        $innerData["pubDate"] = $pubDate;

        // fill one index of the outerData array
        $outerData["data".$counter] = $innerData;

        // make all the variables blank for the next iteration of the loop
        $title = "";
        $description = "";
        $link = "";
        $pubDate = "";
        $insideitem = false;

        // add one to the counter
        $counter++;
    }
}

function characterData($parser, $data) {
    global $insideitem, $tag, $title, $description, $link, $pubDate;
    if ($insideitem) {
    switch ($tag) {
        case "TITLE":
        $title .= $data;
        break;
        case "DESCRIPTION":
        $description .= $data;
        break;
        case "LINK":
        $link .= $data;
        break;
        case "PUBDATE":
        $pubDate .= $data;
        break;
    }
    }
}


// Create an XML parser 
$xml_parser = xml_parser_create(); 

// Set the functions to handle opening and closing tags 
xml_set_element_handler($xml_parser, "startElement", "endElement"); 

// Set the function to handle blocks of character data 
xml_set_character_data_handler($xml_parser, "characterData"); 

// if you started with feed:// fix it to html://



// Open the XML file for reading
$feedzeroFp = fopen($feedzero, 'r') or die("Error reading RSS data."); 
$feedoneFp = fopen($feedone, 'r') or die("Error reading RSS data."); 
$feedtwoFp = fopen($feedtwo, 'r') or die("Error reading RSS data."); 
$feedthreeFp = fopen($feedthree, 'r') or die("Error reading RSS data."); 
$feedfourFp = fopen($feedfour, 'r') or die("Error reading RSS data."); 
// Read the XML file 4KB at a time 
while ($data = fread($feedoneFp, 4096)) 
//Parse each 4KB chunk with the XML parser created above 
    xml_parse($xml_parser,$data,feof($feedoneFp)) 
        //Handle errors in parsing 
        or die(sprintf("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser))); 



// Close the XML file 
fclose($feedoneFp); 

while ($data = fread($feedtwoFp, 4096)) 
//Parse each 4KB chunk with the XML parser created above 
    xml_parse($xml_parser,$data,feof($feedtwoFp)) 
        //Handle errors in parsing 
        or die(sprintf("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser))); 



// Close the XML file 
fclose($feedtwoFp); 
while ($data = fread($feedthreeFp, 4096)) 
//Parse each 4KB chunk with the XML parser created above 
    xml_parse($xml_parser,$data,feof($feedthreeFp)) 
        //Handle errors in parsing 
        or die(sprintfs("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser))); 



// Close the XML file 
fclose($feedthreeFp); 
while ($data = fread($feedfourFp, 4096)) 
//Parse each 4KB chunk with the XML parser created above 
    xml_parse($xml_parser,$data,feof($feedfourFp)) 
        //Handle errors in parsing 
        or die(sprintf("XML error: %s at line %d",
            xml_error_string(xml_get_error_code($xml_parser)),
            xml_get_current_line_number($xml_parser))); 



// Close the XML file 
fclose($feedfourFp); 



// Free up memory used by the XML parser 
xml_parser_free($xml_parser);

?>
  • 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-19T02:20:08+00:00Added an answer on May 19, 2026 at 2:20 am

    You cant require the same “parser” more than once because youve already defined the functions in that file. You need to restructure your code:

    In parser.functions.php:

    function startElement($parser, $name, $attrs) {
        global $insideitem, $tag, $title, $description, $link, $pubDate;
        if ($insideitem) {
            $tag = $name;
        } elseif ($name == "ITEM") {
            $insideitem = true;
        } }
    function endElement($parser, $name) {
        global $insideitem, $tag, $counter, $show, $showHTML, $outerData;
        global $title, $description, $link, $pubDate;
        if ($name == "ITEM" && $counter < $show) {
            echo "<table>
                    <tr>
                      <td>
    
            <a href=\"".htmlspecialchars($description)."\">".htmlspecialchars($description)."</a>
                      </td>
                    </tr>";
    
    
            // if you chose to show the HTML
            if ($showHTML) {
                $title = htmlspecialchars($title);
                $description = htmlspecialchars($description);
                $link = htmlspecialchars($link);
                $pubDate = htmlspecialchars($pubDate);
    
            // if you chose not to show the HTML
            } else {
                $title = strip_tags($title);
                $description = strip_tags($description);
                $link = strip_tags($link);
                $pubDate = strip_tags($pubDate);
            }
    
            // fill the innerData array
            $innerData["title"] = $title;
            $innerData["description"] = $description;
            $innerData["link"] = $link;
            $innerData["pubDate"] = $pubDate;
    
            // fill one index of the outerData array
            $outerData["data".$counter] = $innerData;
    
            // make all the variables blank for the next iteration of the loop
            $title = "";
            $description = "";
            $link = "";
            $pubDate = "";
            $insideitem = false;
    
            // add one to the counter
            $counter++;
        }
    }
    
    function characterData($parser, $data) {
        global $insideitem, $tag, $title, $description, $link, $pubDate;
        if ($insideitem) {
        switch ($tag) {
            case "TITLE":
            $title .= $data;
            break;
            case "DESCRIPTION":
            $description .= $data;
            break;
            case "LINK":
            $link .= $data;
            break;
            case "PUBDATE":
            $pubDate .= $data;
            break;
        }
        }
    }
    

    In your actual page php files:

    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    $pubDate = "";
    $show= 50;
    $feedzero = "http://feeds.finance.yahoo.com/rss/2.0/category-stocks?region=US&lang=en-US"; $feedone = "http://feeds.finance.yahoo.com/rss/2.0/category-ideas-and-strategies?region=US&lang=en-US"; 
    $feedtwo  = "http://feeds.finance.yahoo.com/rss/2.0/category-earnings?region=US&lang=en-US"; $feedthree = "http://feeds.finance.yahoo.com/rss/2.0/category-bonds?region=US&lang=en-US";
    $feedfour  = "http://feeds.finance.yahoo.com/rss/2.0/category-economy-govt-and-policy?region=US&lang=en-US";
    
    $insideitem = false;
    $counter = 0;
    $outerData;
    
    require_once('path/to/parser.functions.php');
    
    // Create an XML parser 
    $xml_parser = xml_parser_create(); 
    
    // Set the functions to handle opening and closing tags 
    xml_set_element_handler($xml_parser, "startElement", "endElement"); 
    
    // Set the function to handle blocks of character data 
    xml_set_character_data_handler($xml_parser, "characterData"); 
    
    // if you started with feed:// fix it to html://
    
    
    
    // Open the XML file for reading
    $feedzeroFp = fopen($feedzero, 'r') or die("Error reading RSS data."); 
    $feedoneFp = fopen($feedone, 'r') or die("Error reading RSS data."); 
    $feedtwoFp = fopen($feedtwo, 'r') or die("Error reading RSS data."); 
    $feedthreeFp = fopen($feedthree, 'r') or die("Error reading RSS data."); 
    $feedfourFp = fopen($feedfour, 'r') or die("Error reading RSS data."); 
    // Read the XML file 4KB at a time 
    while ($data = fread($feedoneFp, 4096)) 
    //Parse each 4KB chunk with the XML parser created above 
        xml_parse($xml_parser,$data,feof($feedoneFp)) 
            //Handle errors in parsing 
            or die(sprintf("XML error: %s at line %d",
                xml_error_string(xml_get_error_code($xml_parser)),
                xml_get_current_line_number($xml_parser))); 
    
    
    
    // Close the XML file 
    fclose($feedoneFp); 
    
    while ($data = fread($feedtwoFp, 4096)) 
    //Parse each 4KB chunk with the XML parser created above 
        xml_parse($xml_parser,$data,feof($feedtwoFp)) 
            //Handle errors in parsing 
            or die(sprintf("XML error: %s at line %d",
                xml_error_string(xml_get_error_code($xml_parser)),
                xml_get_current_line_number($xml_parser))); 
    
    
    
    // Close the XML file 
    fclose($feedtwoFp); 
    while ($data = fread($feedthreeFp, 4096)) 
    //Parse each 4KB chunk with the XML parser created above 
        xml_parse($xml_parser,$data,feof($feedthreeFp)) 
            //Handle errors in parsing 
            or die(sprintfs("XML error: %s at line %d",
                xml_error_string(xml_get_error_code($xml_parser)),
                xml_get_current_line_number($xml_parser))); 
    
    
    
    // Close the XML file 
    fclose($feedthreeFp); 
    while ($data = fread($feedfourFp, 4096)) 
    //Parse each 4KB chunk with the XML parser created above 
        xml_parse($xml_parser,$data,feof($feedfourFp)) 
            //Handle errors in parsing 
            or die(sprintf("XML error: %s at line %d",
                xml_error_string(xml_get_error_code($xml_parser)),
                xml_get_current_line_number($xml_parser))); 
    
    
    
    // Close the XML file 
    fclose($feedfourFp); 
    
    
    
    // Free up memory used by the XML parser 
    xml_parser_free($xml_parser);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get this working but for some reason it's just not right.
I can't wrap my head around this for some reason. I'm trying to get
For some reason I can't get this to work. It pulls the name and
For some reason I can't get this script to run when I add the
This is kind of embarrassing but I cannot for some reason get his CSS
Associations: location has_many :comments comment belongs_to :location For some reason, this GET: /locations/5/comments.json is
I use CSS transitions fairly regularly and for some reason I cannot get them
For some reason the script below is not working. This is the code I
for some reason this code throws an error // map<int, AnItem> roomlist; // map<string,
When i try to submit the form below i get this error WARNING: Can't

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.