On PHP versions prior to PHP 5.3.3, the parse_url function generates warnings when dealing with invalid URLs.
Since this function should return FALSE when having a seriously malformed URL as an argument, a quick solution is to suppress warnings by using an ‘@’ character in front of function calls.
Considering that this is a small PHP bug which was fixed on PHP 5.3.3, it is pointless to write a new custom URL Parser to solve the issue.
By replacing:
$parsed=parse_url($your_url);
with:
$parsed=@parse_url($your_url);
warnings like:
[23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63 [23-Dec-2013 13:24:02] PHP Warning: parse_url(javascript://) [<a href='function.parse-url'>function.parse-url</a>]: Unable to parse URL in /home/username/public_html/wp-content/plugins/pluginname/script.php on line 63
will be suppressed.
Using @parse_url() all warnings (see the above log) and error messages generated by this function will be ignored (silenced).
I don’t recommended using ‘@’ to ignore errors and warnings, but in this particular case will help suppressing warnings for servers running older PHP versions.