How can one ensure proper formatting of PHP code when posting on forums to maintain readability?

To ensure proper formatting of PHP code when posting on forums for readability, use code tags or a code block to separate the code from the rest of the text. This will make it easier for others to read and understand the code. Additionally, indent your code properly to improve readability.

<?php
// Example PHP code snippet
$variable = 'Hello, World!';
echo $variable;
?>