What are best practices for integrating PHP code into Joomla websites?

When integrating PHP code into Joomla websites, it is important to follow best practices to ensure compatibility and security. One common approach is to create a custom Joomla module or plugin that encapsulates the PHP code, allowing for easy integration and maintenance.

<?php
defined('_JEXEC') or die;

// Your PHP code here
echo "Hello, Joomla!";
?>