Okay, I can only recreate this one way, it is a bit hard to explain, so here it goes:
Let’s say you have the following post (in pre tags so you can see it unhighlighted):
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
Now, when I highlight the code and press the code button, it should do three things. 1) add a new line between the text and the code and 2) indent the code part by 4 spaces on each line, 3) add a new line after the code.
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
Output:
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
Okay, so far so good. If I remove the newline between the text at the top of the code and the code, like so, the highlighting will fail (it seems that new line is very important).
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
Output:
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
I should note that you can remove the optional ending newline without any issue.
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
Output:
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
You can even put text immediately after the last indented line of code
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
More text can be here without any issue.
Output:
This is my post, here is the code that isn't working.
$fp = fopen('/pathto-the-file/data.csv', 'a');
fwrite($fp, $name . ',' . $lastname . ',' . $address . ',' . $city . ',' . $country . ',' . $birthday . ',' . $email . ',' . $phone . ',' . $room . ',' . $gender . ',' . $comment . ',' . PHP_EOL);
fclose($fp);
More text can be here without any issue.
By chance on the times it failed, was the newline between your opening text and your code block removed (or not inserted)?