3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
function convertLHS( $lhs ) { global $x400Delimiter; $retval = ""; $eles = explode('.',$lhs ); $num = count($eles); if ( $num == 1) $retval = "S=" . strtoupper($eles[0]) . $x400Delimiter; if ( $num == 2) $retval = "S=" . strtoupper($eles[1]) . $x400Delimiter . "G=" . strtoupper($eles[0]) . $x400Delimiter; if ( $num > 2) $retval = "S=" . strtoupper($eles[$num-1]) . $x400Delimiter . getInitials($lhs) . "G=" . strtoupper($eles[0]) . $x400Delimiter; return $retval ; } // domain element // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function convertSubDomain( $domain ) { global $x400Delimiter; $retval = ""; $eles = explode('.',$domain ); $num = count($eles); if ( $num == 1) return "OU=" . strtoupper($eles[0]) . $x400Delimiter; } // sort initials if they exist // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function getInitials($lhs) { global $x400Delimiter; $retval = "I="; $eles = explode('.',$lhs ); $num = count($eles); for ($i=1;$i<$num-1;$i++) { $subStr = $eles[$i]; // test if multiple if (strlen($subStr) > 1) { $arr = str_split($subStr); $subStr = implode('.',$arr); } $retval .= strtoupper($subStr) . '.'; } return rtrim($retval,'.' ). $x400Delimiter; } // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function normaliseX400($x400) { return $x400; } // get the posted search string $searchString = $_GET['searchStr']; $x400 = ""; try { global $x400Prefix; global $x400Postfix; $lhsrhs = explode("@",$searchString); $emailComps['domain'] = $lhsrhs[1]; $emailComps['name'] = $lhsrhs[0]; $emailComps['subdomain'] = explode(".x.gsi.gov.uk",$emailComps['domain'] )[0]; $x400 = normaliseX400 ( convertSubdomain($emailComps['subdomain'] ) . convertLHS($emailComps['name']) ); $x400 = $x400Prefix . $x400 . $x400Postfix; } catch (Exception $e) { throw new Exception( 'Failed to analyse email ['.$searchString.'] ', $e); } //print_r($emailComps); // output the basic html ?> <p>Found a [ <?php echo strtoupper($emailComps['subdomain']); ?> ] confidential other government department address in ( <?php echo $searchString ; ?> ).</p> <p>Click here to email: <a href= "mailto:%3C?php%20echo%20urlencode($x400);%20?%3E"> X.400 address for <?php echo $emailComps['name'] ?> </a><br></p> <address> <?php echo $x400 ?> </address>
Output for 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
function convertLHS( $lhs ) { global $x400Delimiter; $retval = ""; $eles = explode('.',$lhs ); $num = count($eles); if ( $num == 1) $retval = "S=" . strtoupper($eles[0]) . $x400Delimiter; if ( $num == 2) $retval = "S=" . strtoupper($eles[1]) . $x400Delimiter . "G=" . strtoupper($eles[0]) . $x400Delimiter; if ( $num > 2) $retval = "S=" . strtoupper($eles[$num-1]) . $x400Delimiter . getInitials($lhs) . "G=" . strtoupper($eles[0]) . $x400Delimiter; return $retval ; } // domain element // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function convertSubDomain( $domain ) { global $x400Delimiter; $retval = ""; $eles = explode('.',$domain ); $num = count($eles); if ( $num == 1) return "OU=" . strtoupper($eles[0]) . $x400Delimiter; } // sort initials if they exist // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function getInitials($lhs) { global $x400Delimiter; $retval = "I="; $eles = explode('.',$lhs ); $num = count($eles); for ($i=1;$i<$num-1;$i++) { $subStr = $eles[$i]; // test if multiple if (strlen($subStr) > 1) { $arr = str_split($subStr); $subStr = implode('.',$arr); } $retval .= strtoupper($subStr) . '.'; } return rtrim($retval,'.' ). $x400Delimiter; } // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function normaliseX400($x400) { return $x400; } // get the posted search string $searchString = $_GET['searchStr']; $x400 = ""; try { global $x400Prefix; global $x400Postfix; $lhsrhs = explode("@",$searchString); $emailComps['domain'] = $lhsrhs[1]; $emailComps['name'] = $lhsrhs[0]; $emailComps['subdomain'] = explode(".x.gsi.gov.uk",$emailComps['domain'] )[0]; $x400 = normaliseX400 ( convertSubdomain($emailComps['subdomain'] ) . convertLHS($emailComps['name']) ); $x400 = $x400Prefix . $x400 . $x400Postfix; } catch (Exception $e) { throw new Exception( 'Failed to analyse email ['.$searchString.'] ', $e); } //print_r($emailComps); // output the basic html ?> <p>Found a [ Notice: Undefined variable: emailComps in /in/9OUdg on line 129 ] confidential other government department address in ( Notice: Undefined variable: searchString in /in/9OUdg on line 131 ).</p> <p>Click here to email: <a href= "mailto:%3C?php%20echo%20urlencode($x400);%20?%3E"> X.400 address for Notice: Undefined variable: emailComps in /in/9OUdg on line 137 </a><br></p> <address> Notice: Undefined variable: x400 in /in/9OUdg on line 140 </address>
Output for 4.3.0 - 5.4.45
function convertLHS( $lhs ) { global $x400Delimiter; $retval = ""; $eles = explode('.',$lhs ); $num = count($eles); if ( $num == 1) $retval = "S=" . strtoupper($eles[0]) . $x400Delimiter; if ( $num == 2) $retval = "S=" . strtoupper($eles[1]) . $x400Delimiter . "G=" . strtoupper($eles[0]) . $x400Delimiter; if ( $num > 2) $retval = "S=" . strtoupper($eles[$num-1]) . $x400Delimiter . getInitials($lhs) . "G=" . strtoupper($eles[0]) . $x400Delimiter; return $retval ; } // domain element // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function convertSubDomain( $domain ) { global $x400Delimiter; $retval = ""; $eles = explode('.',$domain ); $num = count($eles); if ( $num == 1) return "OU=" . strtoupper($eles[0]) . $x400Delimiter; } // sort initials if they exist // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function getInitials($lhs) { global $x400Delimiter; $retval = "I="; $eles = explode('.',$lhs ); $num = count($eles); for ($i=1;$i<$num-1;$i++) { $subStr = $eles[$i]; // test if multiple if (strlen($subStr) > 1) { $arr = str_split($subStr); $subStr = implode('.',$arr); } $retval .= strtoupper($subStr) . '.'; } return rtrim($retval,'.' ). $x400Delimiter; } // --------------------------------------- // Function Declaration // ---------------------------------------- // name: // does: // accepts: // returns: function normaliseX400($x400) { return $x400; } // get the posted search string $searchString = $_GET['searchStr']; $x400 = ""; try { global $x400Prefix; global $x400Postfix; $lhsrhs = explode("@",$searchString); $emailComps['domain'] = $lhsrhs[1]; $emailComps['name'] = $lhsrhs[0]; $emailComps['subdomain'] = explode(".x.gsi.gov.uk",$emailComps['domain'] )[0]; $x400 = normaliseX400 ( convertSubdomain($emailComps['subdomain'] ) . convertLHS($emailComps['name']) ); $x400 = $x400Prefix . $x400 . $x400Postfix; } catch (Exception $e) { throw new Exception( 'Failed to analyse email ['.$searchString.'] ', $e); } //print_r($emailComps); // output the basic html ?> <p>Found a [ ] confidential other government department address in ( ).</p> <p>Click here to email: <a href= "mailto:%3C?php%20echo%20urlencode($x400);%20?%3E"> X.400 address for </a><br></p> <address> </address>