deconf.com

  • Home
  • Analytics Insights
  • Search Engine Insights

PHP parse_url fix: Unable to Parse URL

December 31, 2013 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:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

Related

Tags: PHP Scripts, Tweaks

Follow deconf.com

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

Categories

  • WordPress Plugins
  • Joomla! Extensions
  • Analytics Insights FAQ
  • Tutorials
  • Donate or Contribute
  • Contact
  • Data Usage Policy for my Extensions
  • Privacy Policy
  • Tutorials & Tips

Copyright © 2025 · DeConf.com