What are the best practices for maintaining clean and structured code when not using a template system in PHP?

When not using a template system in PHP, it's important to maintain clean and structured code by separating the HTML presentation from the PHP logic. One way to achieve this is by using the MVC (Model-View-Controller) design pattern. This involves separating the business logic (Model), presentation logic (View), and user input handling (Controller) into separate components.

// Example of implementing MVC pattern in PHP without using a template system

// Model - Contains the business logic
class User {
    public function getUserData($userId) {
        // Logic to fetch user data from database
        return $userData;
    }
}

// View - Contains the presentation logic
class UserView {
    public function displayUserData($userData) {
        // HTML code to display user data
    }
}

// Controller - Handles user input and interacts with Model and View
class UserController {
    public function showUserData($userId) {
        $userModel = new User();
        $userData = $userModel->getUserData($userId);

        $userView = new UserView();
        $userView->displayUserData($userData);
    }
}

// Usage
$userId = 1;
$userController = new UserController();
$userController->showUserData($userId);