eXorithm – Execute Algorithm: View / Run Algorithm simple_calculator

function simple_calculator ($number1$operator$number2

{

  // calculator

  

  switch ($operator) {

    case "plus"

      $res = $number1$number2

      break

    case "minus"

      $res = $number1$number2

      break

    case "times"

      $res = $number1$number2

      break

    case "divided by"

      $res = $number1$number2

      break

    default

      $res = 0;

  }

  

  return $res

eXorithm – Execute Algorithm: View / Run Algorithm show_address

function show_address ($address

{

  $data = file_get_contents"http://maps.googleapis.com/maps/api/geocode/json?address="urlencode$address)."&sensor=false");

  $obj = json_decode$data);

  if ($obj) {

    if (isset$obj->results[0]->geometry->location)) {

      $loc = $obj->results[0]->geometry->location;

      return array'latitude'=>$loc->lat, 'longitude'=>$loc->lng);

    } else {

      throw new Exception'Lookup failed and/or address does not exist!');

    }

  } else {

    throw new Exception'Lookup failed and/or address does not exist!');

  }

eXorithm – Execute Algorithm: View / Run Algorithm scale_image

function scale_image ($image$width$height$percent
{
  $ewidth = imagesx$image);
  $eheight = imagesy$image);
  
  if ($percent) {
    $width = round(($width/100)*$ewidth);
    $height = round(($height/100)*$eheight);
  }
  
  $image2 = image_create_alpha$width$height);
  
  for ($x=0;$x$width$x++) {
    $x1 = floor$x * ($ewidth$width));
    for ($y=0;$y$height$y++) {
      $y1 = floor$y * ($eheight$height));
      $index = imagecolorat$image$x1$y1);
      $color = imagecolorsforindex$image$index);
      $trans = imagecolorallocatealpha$image2
                                       $color'red'], 
                                       $color'green'], 
                                       $color'blue'], 
                                       $color'alpha']);
      imagesetpixel$image2$x$y$trans);
    }
  }
  
  return $image2

eXorithm – Execute Algorithm: View / Run Algorithm sort_multi_array

function sort_multi_array ($array$key

{

  $keys = array();

  for ($i=1;$ifunc_num_args();$i++) {

    $keys$i-1] = func_get_arg$i);

  }

  

  // create a custom search function to pass to usort

  $func = function ($a$buse ($keys) {

    for ($i=0;$icount$keys);$i++) {

      if ($a$keys$i]] != $b$keys$i]]) {

        return ($a$keys$i]] < $b$keys$i]]) ? -1 : 1;

      }

    }

    return 0;

  };

  

  usort$array$func);

  

  return $array

eXorithm – Execute Algorithm: View / Run Algorithm rot13

function rot13 ($string

{

  for$i=0;$istrlen$string);$i++) {

    $jord$string$i]);

    if ((($j>=ord"n")) & ($j<=ord"z"))) | ($j>=ord"N")) & ($j<=ord"Z"))) {

      $j$j-13;

    }

    elseif ((($j>=ord"a")) & ($j<=ord"m"))) | ($j>=ord"A")) & ($j<=ord"M"))) {

      $j$j+13;

    }

    $new.=chr$j);

  }

  return$new);