• What this does is open/read the xml, search for anything that contains example.com and replace it by sub.demo.com

    libxml_use_internal_errors(TRUE);
    	$dom = new DOMDocument;
    	$dom->Load('/home/user/public_html/newfeed.xml');
    var_dump(libxml_get_errors());
    	if ($dom->validate()) {
        	echo " This xml is valid!\n";
            $xmlor = '/home/user/public_html/newfeed.xml';
    
            // open file and prepare mods
            $fh = fopen($xmlor, 'r+');
            $data = fread($fh, filesize($xmlor));
            echo "Opening local XML..." . PHP_EOL;
            $new_data = str_replace("example.com", "sub.demo.com", $data);
            fclose($fh);
    
    // run mods
    $fh = fopen($xmlor, 'r+');
    fwrite($fh, $new_data);
    echo "Updated feed URL in local XML..." . PHP_EOL;
    fclose($fh);
    
    	}

    It’s not outputting errors, but it also isn’t making any changes to the file.

    Help is appreciated, thank you in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    This appears to be off topic, it’s unrelated to anything WordPress.

    DOMDocument class is not supported by default in many PHP installations. You should enable error reporting in your environment, or check your error logs for indications why this isn’t working. It could be a file write permission issue. The user that is running PHP must have the proper permission. This user is unrelated to your login, it is defined in httpd.conf.

    Thread Starter pitbullgti

    (@pitbullgti)

    Thank you for your reply.
    It is part of a wordpress press Plugin i’m making for personal use. Not the first time someone said that to me…what’s missing to make it wordpress-iesh ? Maybe the code i didnt paste? Or do I need something else? I dont get it! ??
    This code is working properly outside wordpress. As for error log, for some reason, this specific error (if there is one), is not showing up on logs, or even when php debug is on. No error.

    Moderator bcworkz

    (@bcworkz)

    We can say it’s a WP issue since it is within that environment the problem occurs, since it works fine outside of WP ?? The code itself uses no WP resources, so on first blush it appears to not be WP related.

    You’re getting all the var_dump and echo output as expected? I have to think not since the code otherwise works. Then the issue is how the code is called. Otherwise all I can suggest is basic debugging. Output intermediate values to zero in on exactly what line is failing. Usually the problem becomes apparent in the process, but it shouldn’t be any different than outside of WP. The only thing possibly different is the user PHP is running under, but permission failures should throw error messages.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘replace parts of content within a xml file’ is closed to new replies.