Deconf.com

  • WordPress Plugins
  • Joomla Extensions

PHP parse_url fix: Unable to Parse URL

Last Updated on August 26, 2014 by Alin Marcu

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.

Share this:

  • Twitter
  • Facebook

Follow deconf.com

Subscribe to receive free updates when new plugins, tutorials or posts are available

Categories

  • WordPress
  • Joomla
  • Reviews
  • Tutorials
  • Articles
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Donate or Contribute
  • Contact
  • Data Usage Policy for my Extensions
  • Privacy Policy

Copyright © 2019 · DeConf.com