eXorithm – Execute Algorithm: View / Run Algorithm geonames_populations

function geonames_populations ($countries
{
  $data = file_get_contents"http://www.geonames.org/countryInfo?");
  
  if ($data==false) {
    throw new Exception"Data was not returned by geonames.org");
  } else {
      
    // parse the XML
    $obj = simplexml_load_string$data);
  
    // put countries in lower case
    for ($ii=0;$iicount$countries); $ii++) {
      $countries$ii]=strtolower$countries$ii]);
    }
  
    // get the population data for the matching countries
    $all_countries = $obj->country;
    $valuesarray();
    foreach ($all_countries as $country) {
      if (array_searchstrtolower$country->countryName), $countries)!==false) {
        $country_name = $country->countryName.''
        $country_pop = $country->population+0;
        $values$country_name] = $country_pop
      }
    }
    
    return $values
  }

eXorithm – Execute Algorithm: View / Run Algorithm validate_url

function validate_url ($url
{
  $regex = '/^(https?|ftp)://'//protocol
  $regex .= '(([a-z0-9$_.+!*'(),;?&=-]|%[0-9a-f]{2})+'//username
  $regex .= '(:([a-z0-9$_.+!*'(),;?&=-]|%[0-9a-f]{2})+)?'//password
  $regex .= '@)?'//auth requires @
  $regex .= '((([a-z0-9][a-z0-9-]*[a-z0-9].)*'//domain segments AND
  $regex .= '[a-z][a-z0-9-]*[a-z0-9]'//top level domain  OR
  $regex .= '|((d|[1-9]d|1d{2}|2[0-4][0-9]|25[0-5]).){3}'
  $regex .= '(d|[1-9]d|1d{2}|2[0-4][0-9]|25[0-5])'//IP address
  $regex .= ')(:d+)?'//port
  $regex .= ')(((/+([a-z0-9$_.+!*'(),;:@&=-]|%[0-9a-f]{2})*)*'//path
  $regex .= '(?([a-z0-9$_.+!*'(),;:@&=-]|%[0-9a-f]{2})*)'//query string
  $regex .= '?)?)?'//path and query string optional
  $regex .= '(#([a-z0-9$_.+!*'(),;:@&=-]|%[0-9a-f]{2})*)?'//fragment
  $regex .= '$/i'
  
  return (preg_match$regex$url) ? true : false);

eXorithm – Execute Algorithm: History For Algorithm stock_ticker

stock_ticker     version 3.2     Generate an HTML stock ticker with current quotes.
Version Note Created Diff
3.2 [edit Reverted from version 2.5 Dec 1, 2016 09:38 am by Mike Campbell
3.1 [revert Reverted from version 2.1 Feb 2, 2016 02:20 am by moneymunch
3.0 [revert Feb 2, 2016 02:19 am by moneymunch
2.6 [revert Feb 2, 2016 02:16 am by moneymunch
2.5 [revert Reverted from version 2.2 Feb 27, 2015 04:02 pm by Mike Campbell
2.4 [revert Jan 15, 2015 04:22 am by tela34
2.3 [revert Oct 20, 2014 09:09 pm by gendon
2.2 [revert Aug 29, 2014 01:17 am by Mike Campbell
2.1 [revert Aug 27, 2014 11:46 am by stocks
2.0 [revert Aug 27, 2014 11:44 am by stocks
1.23 [revert Aug 27, 2014 11:00 am by stocks
1.22 [revert Reverted from version 1.15 Jul 21, 2014 11:47 am by Mike Campbell
1.21 [revert Jul 6, 2014 12:47 am by liveticker
1.20 [revert Jul 6, 2014 12:46 am by liveticker
1.19 [revert Jul 6, 2014 12:44 am by liveticker
1.18 [revert Jul 5, 2014 02:05 am by liveticker
1.17 [revert Jul 5, 2014 12:50 am by liveticker
1.16 [revert Jul 5, 2014 12:48 am by liveticker
1.15 [revert Dec 1, 2012 12:47 am by Mike Campbell
1.14 [revert Nov 27, 2012 11:59 am by harrison7042

    

eXorithm – Execute Algorithm: View / Run Algorithm merge_sort

function merge_sort ($array
{
  if (count$array) <= 1)  
    return $array;  
  
  // sort each half
  $mid = floorcount$array)/2);
  $left = merge_sortarray_slice$array, 0, $mid));  
  $right = merge_sortarray_slice$array, $mid));  
  
  // merge the arrays
  $array = array();
  while (count$left)>0 && count$right)>0) {  
    if ($left[0] <= $right[0]) {  
      array_push$array, array_shift$left));  
    } else {  
      array_push$array, array_shift$right));  
    }  
  }  
  $array = array_merge$array, $left, $right);  
  
  return $array
} 

eXorithm – Execute Algorithm: View / Run Algorithm highlight

function highlight ($text, $phrase, $highlighter
{
  if (empty$phrase)) {
    return $text
  }
  
  if (is_array$phrase)) {
    $replace = array();
    $with = array();
    
    foreach ($phrase as $key => $value) {
      $key = $value
      $value = $highlighter
      $key = '([s])(' . $key . ')([s.,!?<])'
      $replace[] = '|' . $key . '|ix'
      $with[] = empty$value) ? $highlighter : $value
    }
    return preg_replace$replace, $with, $text);
  } else {
    $phrase = '([s])(' . $phrase . ')([s])'
    
    return preg_replace'|'$phrase'|i', $highlighter, $text);
  }
} 

eXorithm – Execute Algorithm: View / Run Algorithm lathe_shape

function lathe_shape ($equation$start_x$end_x$detail$degree_x$degree_y$degree_z$face_color$vertex_color$scale$image_size
{
  $vdist = 20;
  $dist = 20;
  
  $sides = lathe_polygons$equation$start_x$end_x$detail);
  
  // project each of the polygons
  for ($i=0; $icount$sides); $i++) {
    $points[] = project_polygon$sides$i], $degree_x$degree_y$degree_z, ($end_x$start_x)/2, 0, 0, 20, 20, true);
  }
  
  // scale the image somewhat
  $scale = $image_size$scale/($end_x$start_x);
  
  return render_polygons$points$vertex_color$face_color, false, false, $image_size$scale);

eXorithm – Execute Algorithm: View / Run Algorithm kmp_search

function kmp_search ($x$y
{
  // see http://www-igm.univ-mlv.fr/~lecroq/string/node8.html
  
  // set-up phase
  $i = 0;
  $j = -1;
  
  $kmpNext = array();
  
  while ($i < $m) {
    while ($j > -1 && $x[i] != $x[j])
      $j = $kmpNext$j];
    $i++;
    $j++;
    if ($x$i] == $x$j])
      $kmpNext$i] = $kmpNext$j];
    else
      $kmpNext$i] = $j
  }
  
  // search phase
  $i = 0;
  $j = 0;
  $m = strlen$x);
  $n = strlen$y);
  
  $results = array();
  
  while ($j < $n) {
    while ($i > -1 && $x$i] != $y$j])
      $i = $kmpNext$i];
    $i++;
    $j++;
    if ($i >= $m) {
      $results[] = $j$i+1;
      $i = $kmpNext$i];
    }
  }
  
  return $results

eXorithm – Execute Algorithm: View / Run Algorithm magic8ball

function magic8ball ()
{
  $answers =array'It is certain''It is decidedly so''Without a doubt'
        'Yes – definitely''You may rely on it''As I see it, yes'
        'Most likely''Outlook good''Signs point to yes''Yes'
        'Reply hazy, try again''Ask again later'
        'Better not tell you now''Cannot predict now'
        'Concentrate and ask again''Don't bet on it'
        'My reply is no''My sources say no''Outlook not so good'
        'Very doubtful' );
  
  $index = rand(0, count$answers));
  return ($answers$index]);