What are the best practices for passing parameters to a PHP function for link manipulation?

When passing parameters to a PHP function for link manipulation, it is best practice to sanitize and validate the input to prevent any security vulnerabilities or unexpected behavior. One way to achieve this is by using PHP's filter_input() function to sanitize and validate the input parameters before using them in the function.

function manipulate_link($url) {
    // Sanitize and validate the input parameter
    $url = filter_input(INPUT_GET, $url, FILTER_SANITIZE_URL);

    // Perform link manipulation logic here
    // For example, adding query parameters or modifying the URL

    return $url;
}

// Example usage
$link = manipulate_link($_GET['url']);
echo $link;