PHP script for getting post data from Tampermonkey script
A somewhat better solution would be to take advantage of the fact that PHP auto-generates arrays from REQUEST data, if the fields are named correctly. Thus I propose changing the code posted by you to the following:

var date = new Date();
var data = "date=" + date +
           "&amp;accountsnumber=" + accountsCount +
    accounts.reduce(function (prev, account, n) {
        // Note the use of square brackets here, they tell PHP to create an array.
        return prev + "&amp;d[" + n + "][accountname]=" + account.name +
            "&amp;d[" + n + "][credits]=" + account.credits;
    }, '');


As for the PHP code, it'll look like this:

&lt;?php
// Renamed this to save_contents () as that is what we're actually doing.
function save_contents()
{
    // Use intval () here to ensure that we do indeed have an integer, and not some random injection code.
    $accountnumber = intval ($_POST['accountsnumber']);

    // Validate with DateTime to verify that this is indeed a valid date.
    $date = new DateTime ($_POST['date'], new DateTimeZone (DEFAULT_TIMEZONE));

    // Format the date, and use htmlspecialchars to ensure HTML-conformity of the output.
    $str = '&lt;strong&gt;Updated last: %s&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;';
    $output = sprintf ($str, htmlspecialchars ($date-&gt;format ("Y-m-d")))

    // Create a string template to use with sprintf (), to make the code easier to read.
    $str = '&lt;strong&gt;Account %1$d&lt;/strong&gt;&lt;br /&gt;(%2$s)&lt;br /&gt;CREDITS&lt;br /&gt;%3$s&lt;br /&gt;-&lt;br /';

    for ($id = 1; $id &lt;= $accountnumber; $id++) {            
        // Use htmlspecialchars to protect against XSS.
        $accName = htmlspecialchars ($_POST['d'][$id]['accountname']);
        $credits = htmlspecialchars ($_POST['d'][$id]['credits']);

        $output .= sprintf ($str, $id, $accName, $credits);
    }

    file_put_contents("content.html", rtrim ($output, '&lt;br /&gt;-&lt;br /&gt;'));
}


As you can see I've added some basic protection against attackers as well, as the code posted by you is woefully insecure. Basically allowing whomever wants full access to your web-server, to do whatever they like!
Check out OWASP for more information.