I have simple question. User supplies URL to my PHP script where I fetch the page from the URL and parse it and show some snippet to user. Now I want to sanitize or better escape the URL so it is safe for me to fetch it by using file_get_contents().
My simplified code looks like this:
$url = $_POST['url'];
$html = file_get_contents($url);
First thing what came to my mind is to use regex for catching evil URL, but I don't think it is efficient and better would be escape the whole URL. But what PHP function can I use for escaping URL for use in file_get_contents() function ?