Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Guacamole;
- // why does php not have a built in slice method?
- function str_slice() {
- $args = func_get_args();
- $str = $args[0];
- $str_length = strlen($str);
- $start = $args[1];
- $end = $args[2];
- if ($start >= $str_length) {
- return "";
- }
- if ($start < 0) {
- if ($start < - $str_length) {
- $start = 0;
- } else {
- $start = $str_length - abs($start);
- }
- }
- if ($end <= $start) {
- return "";
- }
- if ($end > $str_length) {
- $end = $str_length;
- }
- $length = $end - $start;
- return substr($str, $start, $length);
- }
- function decodeResponse($str) {
- $pos=-1;
- $sections = [];
- for(;;) {
- $len = strpos($str,'.',$pos+1);
- if($len==-1) {break;}
- $pos = intval(str_slice($str,$pos+1,$len))+$len+1;
- array_push($sections, str_slice($str,$len+1,$pos));
- if(str_slice($str,$pos,$pos+1)==';'){
- break;
- }
- }
- return $sections;
- }
- function encodeGuac($cypher) {
- $command='';
- for($i=0;$i<count($cypher);$i++){
- $current=$cypher[$i];
- $command.=strval(strlen($current)).".".$current;
- $command.=($i<count($cypher)-1?',':';');
- }
- return $command;
- }
- ?>
Add Comment
Please, Sign In to add comment