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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:34:33+00:00 2026-06-17T17:34:33+00:00

I’m now using the function fwrite(); in PHP. But i want to locate my

  • 0

I’m now using the function fwrite(); in PHP. But i want to locate my new things after a specific rule.

This wil be the output.

<?xml version="1.0" encoding="utf-8" ?> 
<logs>
    <log type="text">the new log</log>
    <log type="text>the old log</log>
    <log type="login">some other log.</log>
</logs>

How can i get the new log in the new log and not on the end. I only can find something like file_get_contents and then str_replace. But that seems really not efficient.

My php Code:

$file = $this->path.'logs.xml';
    // Open our file. And Create file if it doesn't exsist
    $fopen = fopen($file, "w+");

    // Looks if file is empty.
    if(filesize($file) == 0) {

        /*
         * Put your data in XML data.
         */
        $xmlData = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \r\n";
        $xmlData .= "<logs> \r\n";
            $xmlData .= "\t<log type=\"".$data[0]."\">\r\n";
                $xmlData .= "\t\t<author>".$data[1]."</author>\r\n";
                $xmlData .= "\t\t<action>".$data[2]."</action>\r\n";
                $xmlData .= "\t\t<result>".$data[3]."</result>\r\n";
                $xmlData .= "\t\t<note>".$data[4]."</note>\r\n";
            $xmlData .- "\t</log>\r\n";
        $xmlData .= "</logs>";

    } else {



    }

    if(is_writeable($file)) {

        fwrite($fopen, $xmlData);
        return true;

    }
    return false;
    fclose($fopen);

Sincerely thank you.

  • 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-17T17:34:34+00:00Added an answer on June 17, 2026 at 5:34 pm

    Well, you’re lucky your data is in XML. PHP has got a bunch of easy to use libraries (extensions) that deal with XML data. For example SimpleXML or the more capable DOM (both extension are enabled by default).

    <?php
        $filename = $this->path.'logs.xml';
    
        if (!file_exists($filename)) {
           // Here's your code from above, although it would be easier to use
           // the libraries here, as well
        } else {
           $logs = simplexml_load_file($filename);
           // See if there's a "text" log element
           $txtlog = $logs->xpath('./log[@type = "text"]');
           ...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I want to construct a data frame in an Rcpp function, but when I
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
This could be a duplicate question, but I have no idea what search terms

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.