Convert line of code from PHP 5 to PHP 7
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

The following code works on a server running PHP 5, but doesn't work on a server running PHP 7. I'm looking for someone to rewrite this line of code to work on my PHP 7 server.

$src = (empty($_GET['url'])) ? 'http://randomurl.com/' : addslashes(filter_input(INPUT_GET, 'url', FILTER_SANITIZE_URL));
Tags
PHP
php7

Crowdsource coding tasks.

1 Solution

Winning solution

Use filter_var instead of filter_input

 $url = $_GET['url'];
 $src = (empty($url)) ? 'http://randomurl.com/' : addslashes(filter_var($url, FILTER_SANITIZE_URL));
Source
SilverHood Apps 1 month ago
Thanks, works perfectly!
imokyourok 1 month ago
Most welcome
SilverHood Apps 1 month ago