How can the problem of using PHP variables in URLs while maintaining XHTML 1.0 compliance be resolved?

When using PHP variables in URLs while maintaining XHTML 1.0 compliance, the issue arises because special characters in the variable value can break the XHTML syntax. To resolve this problem, we can use the urlencode() function in PHP to encode the variable value before including it in the URL.

<?php
$variable = "example value with special characters";
$encoded_variable = urlencode($variable);
$url = "http://example.com/page.php?variable=" . $encoded_variable;
?>