3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // $base = 'test image with Ümlaäute und spaäe.jpg'; $nameEncodedFromGWT = 'test%20image%20with%20U%CC%88mlaa%CC%88ute%20und%20spaa%CC%88e.jpg'; $nameEncodedFromPHP = 'test%20image%20with%20%C3%9Cmla%C3%A4ute%20und%20spa%C3%A4e.jpg'; // this is encoded with urlencode() / rawurlencode() // using rawurldecode $nameDecodedFromGWTRaw = to_utf8(rawurldecode($nameEncodedFromGWT)); $nameDecodedFromPHPRaw = rawurldecode($nameEncodedFromPHP); // using urldecode $nameDecodedFromGWTSimple = urldecode($nameEncodedFromGWT); $nameDecodedFromPHPSimple = urldecode($nameEncodedFromPHP); echo 'Name from GWT: ' . $nameEncodedFromGWT . PHP_EOL . 'Decoded using rawurldecode(): ' . $nameDecodedFromGWTRaw . PHP_EOL . 'Decoded using urldecode(): ' . $nameDecodedFromGWTSimple . PHP_EOL . 'String length for rawurldecode(): ' . strlen($nameDecodedFromGWTRaw) . PHP_EOL . 'String length for urldeocde(): ' . strlen($nameDecodedFromGWTSimple) . PHP_EOL . 'Cleaned name for rawurldecode(): ' . cleanImageName($nameDecodedFromGWTRaw) . PHP_EOL . 'Cleaned name for urldecode(): ' . cleanImageName($nameDecodedFromGWTSimple); echo PHP_EOL . '===============================================' . PHP_EOL; echo 'Name from PHP: ' . $nameEncodedFromPHP . PHP_EOL . 'Decoded using rawurldecode(): ' . $nameDecodedFromPHPRaw . PHP_EOL . 'Decoded using urldecode(): ' . $nameDecodedFromPHPSimple . PHP_EOL . 'String length for rawurldecode(): ' . strlen($nameDecodedFromPHPRaw) . PHP_EOL . 'String length for urldecode(): ' . strlen($nameDecodedFromPHPSimple) . PHP_EOL . 'Cleaned name for rawurldecode(): ' . cleanImageName($nameDecodedFromPHPRaw) . PHP_EOL . 'Cleaned name for urldecode(): ' . cleanImageName($nameDecodedFromPHPSimple); function to_utf8( $string ) { // From http://w3.org/International/questions/qa-forms-utf-8.html if ( preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs', $string) ) { return $string; } else { return iconv( 'CP1252', 'UTF-8', $string); } } /** * Uses preg_replace to replace german umlauts */ function cleanImageName($name) { $clean = preg_replace( array( '/\|/', '/[äÄ]/u', '/[öÖ]/u', '/[üÜ]/u', '/ß/', '/([a-zA-Z0-9]+)/i', '/ - /','/ /','/-/','/&/', '/[á|à|À|Á]/u', '/[é|è|É|È]/u', '/[_\x7c-\xff\$\%\=\?\@\(\)§!\|`´\*#;,:\.<>\/"\'#\t\r\n]/' ), array( ' ', 'ae', 'oe', 'ue', 'ss', '$1', ' ', ' ', ' ', 'und', 'a', 'e', ' ', ), $name); return str_replace(' ', '-', $clean); } ?>
based on T1g1O
Output for 4.3.10 - 4.4.9, 5.0.2 - 7.2.0
Name from GWT: test%20image%20with%20U%CC%88mlaa%CC%88ute%20und%20spaa%CC%88e.jpg Decoded using rawurldecode(): test image with Ümlaäute und spaäe.jpg Decoded using urldecode(): test image with Ümlaäute und spaäe.jpg String length for rawurldecode(): 44 String length for urldeocde(): 44 Cleaned name for rawurldecode(): test-image-with-U--mlaa--ute-und-spaa--e-jpg Cleaned name for urldecode(): test-image-with-U--mlaa--ute-und-spaa--e-jpg =============================================== Name from PHP: test%20image%20with%20%C3%9Cmla%C3%A4ute%20und%20spa%C3%A4e.jpg Decoded using rawurldecode(): test image with Ümlaäute und spaäe.jpg Decoded using urldecode(): test image with Ümlaäute und spaäe.jpg String length for rawurldecode(): 41 String length for urldecode(): 41 Cleaned name for rawurldecode(): test-image-with-uemlaaeute-und-spaaee-jpg Cleaned name for urldecode(): test-image-with-uemlaaeute-und-spaaee-jpg
Output for 4.3.3 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 17 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 18 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 19 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 20 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 21 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 22 Name from GWT: test%20image%20with%20U%CC%88mlaa%CC%88ute%20und%20spaa%CC%88e.jpgPHP_EOLDecoded using rawurldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLDecoded using urldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLString length for rawurldecode(): 44PHP_EOLString length for urldeocde(): 44PHP_EOLCleaned name for rawurldecode(): test-image-with-U--mlaa--ute-und-spaa--e-jpgPHP_EOLCleaned name for urldecode(): test-image-with-U--mlaa--ute-und-spaa--e-jpg Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 25 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 25 PHP_EOL===============================================PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 27 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 28 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 29 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 30 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 31 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 32 Name from PHP: test%20image%20with%20%C3%9Cmla%C3%A4ute%20und%20spa%C3%A4e.jpgPHP_EOLDecoded using rawurldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLDecoded using urldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLString length for rawurldecode(): 41PHP_EOLString length for urldecode(): 41PHP_EOLCleaned name for rawurldecode(): test-image-with-uemlaaeute-und-spaaee-jpgPHP_EOLCleaned name for urldecode(): test-image-with-uemlaaeute-und-spaaee-jpg
Output for 4.3.0 - 4.3.2
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 17 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 18 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 19 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 20 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 21 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 22 Name from GWT: test%20image%20with%20U%CC%88mlaa%CC%88ute%20und%20spaa%CC%88e.jpgPHP_EOLDecoded using rawurldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLDecoded using urldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLString length for rawurldecode(): 44PHP_EOLString length for urldeocde(): 44PHP_EOLCleaned name for rawurldecode(): test-image-with-U-emlaa-eute-und-spaa-ee-jpgPHP_EOLCleaned name for urldecode(): test-image-with-U-emlaa-eute-und-spaa-ee-jpg Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 25 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 25 PHP_EOL===============================================PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 27 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 28 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 29 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 30 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 31 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLYTR on line 32 Name from PHP: test%20image%20with%20%C3%9Cmla%C3%A4ute%20und%20spa%C3%A4e.jpgPHP_EOLDecoded using rawurldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLDecoded using urldecode(): test image with Ümlaäute und spaäe.jpgPHP_EOLString length for rawurldecode(): 41PHP_EOLString length for urldecode(): 41PHP_EOLCleaned name for rawurldecode(): test-image-with--uemla-aeute-und-spa-aee-jpgPHP_EOLCleaned name for urldecode(): test-image-with--uemla-aeute-und-spa-aee-jpg