3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tmp = writeBookmark(17); //debug readBookmark($tmp); //debug // Bookmark Encode Function (one site) function writeBookmark($site) { $site = intval($site); $ts = timeStamp(); // calulates the size of the site id (posible options: 1,2,3,4) $site_id_size = strlen($site); // concatonate site id size, timestamp and site id $decoded_num = $site_id_size . $ts . $site; // Encode timestamp (Base 36) $encoded_num = fromDecimalToBase($decoded_num,36); return $encoded_num; //debug } // Bookmark Decode function function readBookmark($bookmark) { // Decode value $decoded_string = fromBaseToDecimal($bookmark, 36); echo $decoded_string . " "; if(!validateBookmark($decoded_string)) echo "Invalid Bookmark"; else if(is_link_expired($decoded_string) echo "Expired Link"; else { // sturf to link location $site_cnt = substr($decoded_string, 0,1); $site_id = substr($decoded_string, -($site_cnt),$site_cnt); $time_stamp = substr($decoded_string, 1,14); echo "site id cnt ". $site_cnt; echo "\ntime stamp ". $time_stamp; echo "\nsite id " . $site_id; // if valid, redirect to link // else redirect to invalide/expired link page }} /* Helper functions */// build timestamp ssmmhhddmmyyyy function timeStamp() { $ts = date('siHdmY'); return $ts;}// base convert (dec to base36)function fromDecimalToBase($in, $to) { $in = (string) $in; $out = ''; for ($i = strlen($in) - 1; $i >= 0; $i--) { $out = base_convert(bcmod($in, $to), 10, $to) . $out; $in = bcdiv($in, $to); } return preg_replace('/^0+/', '', $out);}// base convet (base36 to dec)function fromBaseToDecimal($in, $from) { $in = (string) $in; $out = ''; for ($i = 0, $l = strlen($in); $i < $l; $i++) { $x = base_convert(substr($in, $i, 1), $from, 10); $out = bcadd(bcmul($out, $from), $x); } return preg_replace('/^0+/', '', $out);}function validateBookmark($bm) { // numeric if(!is_numeric($bm)) { echo "nan"; return false; } // between 19 and 16 digits if(strlen($bm) > 19 || strlen($bm) < 16) { echo "outside range"; return false; } // first digit between 1 and 4 $locLength = substr($bm,0,1); if( $locLength <1 || $locLength >4) { echo "bad loc: ".$locLength; return false; } // if is passes all the tests return true return true;}function is_link_expired($ts) { $hou = substr($ts,5,2); $min = substr($ts,3,2); $sec = substr($ts,1,2); $day = substr($ts,7,2); $mon = substr($ts,9,2); $year = substr($ts,11,2); $bm_time = new DateTime($year."-".$mon."-".$day." ".$hou.":".$min.":".$sec); $current_time = new DateTime(); $difference = date_diff($bm_time,$current_time); }function validateURL($str){ return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i',$str);}function sanitize($str){ if(ini_get('magic_quotes_gpc')) $str = stripslashes($str); $str = strip_tags($str); $str = trim($str); $str = htmlspecialchars($str); $str = mysql_real_escape_string($str); return $str;}
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function timeStamp() in /in/CP4KI:10 Stack trace: #0 /in/CP4KI(4): writeBookmark(17) #1 {main} thrown in /in/CP4KI on line 10
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
43.95 ms | 401 KiB | 8 Q