PHP 8.5.0 Released!

Voting

: two minus zero?
(Example: nine)

The Note You're Voting On

lauris () lauris ! lv
11 years ago
Here is utf-8 compatible parse_url() replacement function based on "laszlo dot janszky at gmail dot com" work. Original incorrectly handled URLs with user:pass. Also made PHP 5.5 compatible (got rid of now deprecated regex /e modifier).
<?php
 /**
 * UTF-8 aware parse_url() replacement.
 * 
 * @return array
 */
 function mb_parse_url($url)
 {
 $enc_url = preg_replace_callback(
 '%[^:/@?&=#]+%usD',
 function ($matches)
 {
 return urlencode($matches[0]);
 },
 $url
 );
 
 $parts = parse_url($enc_url);
 
 if($parts === false)
 {
 throw new \InvalidArgumentException('Malformed URL: ' . $url);
 }
 
 foreach($parts as $name => $value)
 {
 $parts[$name] = urldecode($value);
 }
 
 return $parts;
 }
?>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /