3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $s = 'Happy^ hour^ / is fun //'; function filenameEncode($possible_filename){ $fngood = str_replace(array('/',':'), array('^',';'), $possible_filename); return $fngood; } function filenameDecode($possible_filename){ //all single carets need to be replaced with slashes $possible_filename = preg_replace('/([^\^])(\^)([^\^])/im', '$1/$3', $possible_filename); //all semi-colons need to be replaced with colons $possible_filename = preg_replace('/([^;])(;)([^;])/im', '$1:$3', $possible_filename); $fngood = str_replace(array('^',';'), array('/',':'), $possible_filename); return $possible_filename; } echo 's: '.$s."\n"; $t = filenameEncode($s); $u = filenameDecode($t); echo 't: '.$t."\n"; echo 'u: '.$u."\n"; if ($s === $u){ echo 'test passed'; }else{ echo 'test failed'; }
Output for 4.3.0 - 7.1.7, 7.2.0
s: Happy^ hour^ / is fun // t: Happy^ hour^ ^ is fun ^^ u: Happy/ hour/ ^ is fun ^^ test failed
Output for 7.1.10

Process exited with code 137.