How can whitespace removal and URL encoding be implemented in a PHP template system?

Whitespace removal can be implemented by using the `preg_replace` function in PHP to remove all whitespace characters from a given string. URL encoding can be implemented by using the `urlencode` function in PHP to encode a string so that it can be safely used in a URL.

// Whitespace removal
$string = "   Hello,   World!   ";
$clean_string = preg_replace('/\s+/', '', $string);
echo $clean_string;

// URL encoding
$url = "https://www.example.com/page.php?q=hello world";
$encoded_url = urlencode($url);
echo $encoded_url;