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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:37:14+00:00 2026-06-17T07:37:14+00:00

I have this code: $filename = ‘files.xml’; $dom = new DomDocument(); $dom->load($filename); $oldCount =

  • 0

I have this code:

$filename = 'files.xml';
$dom = new DomDocument();

$dom->load($filename);

$oldCount = '';

$newCount = $dom->getElementsByTagName('file')->length;

if($newCount == $oldCount){
echo "There are no new elements in the XML.\n";
}

else {
 echo "New Count is: ".$newCount."\n";
 echo "Old Count is: ".$oldCount."\n";

for ($oldCount =0; $oldCount < $newCount; $oldCount++){
    $file = file_get_contents('files.xml');
    $xml = simplexml_load_string($file); 

    $result = $xml->xpath('file');
    echo "File ".($oldCount+1).": ".$result[$oldCount]."\n\n";
    //echo "Old: ".$oldCount."\n";
    //echo "New: ".$newCount."\n";
   }
   $oldCount = $newCount;
   //echo "Old Count at the end: ".$oldCount."\n";
}
echo "Old Count at the end: ".$oldCount."\n";

What I want to do is ensure that the value of $oldCount is stored at the end such that, if files.xml has the same number of elements inside the , it would display – “There are no new elements in the XML” when the program is run the second time around.

For test purpose, I have 2 elements in my xml, meaning my xml looks like:

<?xml version="1.0"?>
<files>
  <file>.DS_Store</file>
  <file>ID2PDF_log_2.xml</file>
</files>

So, if I run my test.php with only these 2 elements, it should display the info first time. But, the second time I run it, it should display the message.
It’s pretty obvious I am weak at variable scope in PHP.
How can I do this?

  • 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-06-17T07:37:15+00:00Added an answer on June 17, 2026 at 7:37 am

    Command line doesn’t support sessions without workarounds, since sessions generally depend on cookies (which don’t exist in the command-line) or passing around url query parameters.

    Instead, just dump your number out to a file, e.g.

    file_put_contents('count.txt', $count);
    

    then read it in later, e.g.

    $count = file_get_contents('count.txt');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: Dim FILE_NAME As String = C:\filename.txt Dim objWriter As New
I have this code: FileDownloadHandler handler = new FileDownloadHandler(fileName); Browser.AddDialogHandler(handler); //using (new UseDialogOnce(Browser.DialogWatcher, handler))
I have this Code in Form1. Im doing a search for xml files. When
I have this code: public static Account[] LoadXml(string fileName) { Account ths = new
I have this code: filename = tkFileDialog.askopenfilename(initialdir=lists/custom/, filetypes=((Word list, *.tldr), (All files, *.*))) If
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
So I have a program which runs. This is part of the code: FileName
I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code: private static void saveMetricsToCSV(String fileName, double[] metrics) { try {
I have this code: Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); object nullobj = System.Reflection.Missing.Value; object

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.