All pastes #1557035 Raw Edit

Mine

public php v1 · immutable
#1557035 ·published 2009-09-07 11:26 UTC
rendered paste body
<?php/* Acronym Generator By Louis T. */$acronym = new acronym();/* Local word files are set alphabetically. Not all letters need to be used. Files must end in .dic All files need to be in './wordlist/' when using local. Each word must be on it's own line. Example: List of 'A' words must be in 'A.dic' Example file set: $acronym->setFiles('AFYQBG');*/$acronym->setFiles('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); // Set local files/* URL to a list of external words. Don't set this if you want to use local files. When set, local files are ignored. Warning: Will be slower, and can use a lot of bandwidth.*/// $acronym->setRequest("http://nopaste.com/p/aQkrjaB5d/txt");/* To get an array of an acronym, use $acronym->getAcronym(); Array: 0 = real word, 1 = mixed word*/print_r($acronym->getAcronym()); // Print a readable array.class acronym {      private $word;      private $mode;      private $request;      private $error;      private $files;      private $setFiles;      function __construct () {               $this->mode = "l";      }      function getWord () {               if ($this->getInfo('mode') == "e") {                     if (preg_match('@(http://([-\w\.]+)+(:\d+)?(/([\w/_\.\-\:]*(\?\S+)?)?)?)@',$this->getInfo("request"))) {                           $this->word = $this->findExtWord();                       } else {                           $this->error = "Not a valid URL.";                     }               } else if ($this->getInfo('mode') == "l" && $this->getInfo('setFiles') == 1) {                   $this->word = $this->findLocalWord();                } else {                   $this->error = "No local/external files set."; die($this->getInfo('error'));               }      }      function getAcronym () {               $this->getWord();               if (is_null($this->getInfo('error'))) {                    return array($this->getInfo('word'),implode($this->array_shuffle(str_split($this->getInfo('word')))));                  } else {                    return false;               }      }      function findLocalWord () {               $files = str_split($this->getInfo('files'));               $file = "./wordlists/".$files[rand(0,count($files)-1)].".dic";               if (!file_exists($file)) { die("No such file '".$file."'"); }               if ($ret = file($file)) {                    return trim($ret[rand(0,count($ret)-1)]);                 } else {                    $this->error = "Could not get a word. [LOCAL]"; return false;               }      }      function findExtWord () {               $context = array('http'=>array('method'=>"GET",'header'=>"User-agent: Mozilla/5.0"));               if ($ret = file($this->request,FILE_IGNORE_NEW_LINES,stream_context_create($context))) {                    return trim($ret[rand(0,count($ret)-1)]);                 } else {                    $this->error = "Could not get a word. [EXTERNAL]"; return false;               }      }      function array_shuffle ($arr) {               if (shuffle($arr)) { return $arr; } else { return FALSE; }      }      function setRequest ($r) {               if (is_null($r)) { die("Link required to use external words!"); } else { $this->request = $r; $this->mode = "e"; }      }      function setFiles ($f) {               if (is_null($f)) { die("setFiles was used, but was empty."); } else { $this->files = $f; $this->setFiles = 1; }      }      function getInfo ($type) {               switch ($type) {                      case "mode":                           return $this->mode;                           break;                      case "word":                           return $this->word;                           break;                      case "files":                           return $this->files;                           break;                      case "request":                           return $this->request;                           break;                      case "setFiles":                           return $this->setFiles;                           break;                      case "error":                           return $this->error;                           break;                }      }}?>