3v4l.org

run code in 150+ 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 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
s: Happy^ hour^ / is fun // t: Happy^ hour^ ^ is fun ^^ u: Happy/ hour/ ^ is fun ^^ test failed