Skip to content

Instantly share code, notes, and snippets.

Created June 12, 2012 22:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/2920654 to your computer and use it in GitHub Desktop.
Save anonymous/2920654 to your computer and use it in GitHub Desktop.
<?php
/*
* STATEINFO TextMark Dynamic Script.
* Demo of Contextual Responses feature.
* Script assumes TextMark URL of style: http://server.com/script.php?args=\0
* Send a text message with STATEINFO to 41411 to test.
*
* Author: Dan Kamins
* Copyright (c) 2007 TextMarks - http://www.textmarks.com/
*/
/** */
/**
* State Database - contains information about 50 states.
*
* Not directly related to mobile portion - just some data for this demo.
*/
class StateDatabase
{
function addState($sStateName, $sCapitalName, $sStateAbbreviation, $iYearAdmitted)
{
$this->m_mssStateName[$sStateAbbreviation] = $sStateName;
$this->m_mssCapitalName[$sStateAbbreviation] = $sCapitalName;
$this->m_msiYearAdmitted[$sStateAbbreviation] = $iYearAdmitted;
}
function getStateName($sStateAbbreviation) { return @$this->m_mssStateName[$sStateAbbreviation]; }
function getCapitalName($sStateAbbreviation) { return @$this->m_mssCapitalName[$sStateAbbreviation]; }
function getYearAdmitted($sStateAbbreviation) { return @$this->m_msiYearAdmitted[$sStateAbbreviation]; }
function init()
{
$this->addState("Alabama", "Montgomery", "AL", 1819);
$this->addState("Alaska", "Juneau", "AK", 1959);
$this->addState("Arizona", "Phoenix", "AZ", 1912);
$this->addState("Arkansas", "Little Rock", "AR", 1836);
$this->addState("California", "Sacramento", "CA", 1850);
$this->addState("Colorado", "Denver", "CO", 1876);
$this->addState("Connecticut", "Hartford", "CT", 1788);
$this->addState("Delaware", "Dover", "DE", 1787);
$this->addState("Florida", "Tallahassee", "FL", 1845);
$this->addState("Georgia", "Atlanta", "GA", 1788);
$this->addState("Hawaii", "Honolulu", "HI", 1959);
$this->addState("Idaho", "Boise", "ID", 1890);
$this->addState("Illinois", "Springfield", "IL", 1818);
$this->addState("Indiana", "Indianapolis", "IN", 1816);
$this->addState("Iowa", "Des Moines", "IA", 1846);
$this->addState("Kansas", "Topeka", "KA", 1861);
$this->addState("Kentucky", "Frankfort", "KY", 1792);
$this->addState("Louisiana", "Baton Rouge", "LA", 1812);
$this->addState("Maine", "Augusta", "ME", 1820);
$this->addState("Maryland", "Annapolis", "MD", 1788);
$this->addState("Massachusetts", "Boston", "MA", 1788);
$this->addState("Michigan", "Lansing", "MI", 1837);
$this->addState("Minnesota", "St. Paul", "MN", 1858);
$this->addState("Mississippi", "Jackson", "MS", 1817);
$this->addState("Missouri", "Jefferson City", "MO", 1821);
$this->addState("Montana", "Helena", "MT", 1889);
$this->addState("Nebraska", "Lincoln", "NE", 1867);
$this->addState("Nevada", "Carson City", "NV", 1864);
$this->addState("New Hampshire", "Concord", "NH", 1788);
$this->addState("New Jersey", "Trenton", "NJ", 1787);
$this->addState("New Mexico", "Santa Fe", "NM", 1912);
$this->addState("New York", "Albany", "NY", 1788);
$this->addState("North Carolina", "Raleigh", "NC", 1789);
$this->addState("North Dakota", "Bismarck", "ND", 1889);
$this->addState("Ohio", "Columbus", "OH", 1803);
$this->addState("Oklahoma", "Oklahoma City", "OK", 1907);
$this->addState("Oregon", "Salem", "OR", 1859);
$this->addState("Pennsylvania", "Harrisburg", "PA", 1787);
$this->addState("Rhode Island", "Providence", "RI", 1790);
$this->addState("South Carolina", "Columbia", "SC", 1788);
$this->addState("South Dakota", "Pierre", "SD", 1889);
$this->addState("Tennessee", "Nashville", "TN", 1796);
$this->addState("Texas", "Austin", "TX", 1845);
$this->addState("Utah", "Salt Lake City", "UT", 1896);
$this->addState("Vermont", "Montpelier", "VT", 1791);
$this->addState("Virginia", "Richmond", "VA", 1788);
$this->addState("Washington", "Olympia", "WA", 1889);
$this->addState("West Virginia", "Charleston", "WV", 1863);
$this->addState("Wisconsin", "Madison", "WI", 1848);
$this->addState("Wyoming", "Cheyenne", "WY", 1890);
}
private $m_mssStateName = array();
private $m_mssCapitalName = array();
private $m_msiYearAdmitted = array();
}
// Action:
{
// Init State Database:
$sdb = new StateDatabase();
$sdb->init();
// Parse request... assumes TextMark URL set like: http://server.com/script.php?args=\0
$sArgs = @$_REQUEST["args"];
// If no args, then user just sent "STATEINFO", so give them intro:
if ($sArgs == NULL)
{
echo "Rply to this msg with the two letter abbreviation of a state for info about it.";
exit;
}
// Do a state lookup:
$sStateAbbreviation = strtoupper($sArgs);
$sStateName = $sdb->getStateName($sStateAbbreviation);
$sCapitalName = $sdb->getCapitalName($sStateAbbreviation);
$iYearAdmitted = $sdb->getYearAdmitted($sStateAbbreviation);
// Not found in DB?
if ($sStateName == NULL)
{
echo "Unknown state \"$sStateAbbreviation\". Rply with the two letter abbreviation of a state for info about it.";
exit;
}
// Echo state info:
{
echo htmlentities($sStateName) . " (" . htmlentities($sStateAbbreviation) . ")\n-\n";
echo "Capital:\n" . htmlentities($sCapitalName) . "\n-\n";
echo "Admitted:\n" . $iYearAdmitted . "\n-\n";
echo "For more, rply with a 2-letter state abbreviation.";
exit;
}
}
?>
@onetimeone888
Copy link

Gg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment