本文整理汇总了PHP中postcode_to_constituency函数的典型用法代码示例。如果您正苦于以下问题:PHP postcode_to_constituency函数的具体用法?PHP postcode_to_constituency怎么用?PHP postcode_to_constituency使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了postcode_to_constituency函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: api_getDivisions_postcode
function api_getDivisions_postcode($pc)
{
$pc = preg_replace('#[^0-9]#i', '', $pc);
$output = array();
if (is_postcode($pc)) {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
} elseif ($constituency) {
if (is_array($constituency)) {
$constituencies = $constituency;
} else {
$constituencies = array($constituency);
}
foreach ($constituencies as $c) {
$output[] = array('name' => html_entity_decode($c));
}
} else {
api_error('Unknown postcode');
}
} else {
api_error('Invalid postcode');
}
api_output($output);
}
示例2: api_getRepresentatives_postcode
function api_getRepresentatives_postcode($pc)
{
$pc = preg_replace('#[^0-9]#i', '', $pc);
if (is_postcode($pc)) {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
} elseif ($constituency) {
if (is_array($constituency)) {
$constituencies = $constituency;
} else {
$constituencies = array($constituency);
}
$output = array();
foreach ($constituencies as $c) {
$output[] = _api_getMP_constituency($c);
}
api_output($output);
} else {
api_error('Unknown postcode');
}
} else {
api_error('Invalid postcode');
}
}
示例3: api_getconstituency_postcode
function api_getconstituency_postcode($pc)
{
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (validate_postcode($pc)) {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
} elseif ($constituency) {
$output['name'] = html_entity_decode($constituency);
api_output($output);
} else {
api_error('Unknown postcode');
}
} else {
api_error('Invalid postcode');
}
}
示例4: api_getMP_postcode
function api_getMP_postcode($pc)
{
$pc = preg_replace('#[^0-9]#i', '', $pc);
if (is_postcode($pc)) {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
} elseif ($constituency) {
$person = _api_getMP_constituency($constituency);
$output = $person;
api_output($output, strtotime($output['lastupdate']));
} else {
api_error('Unknown postcode');
}
} else {
api_error('Invalid postcode');
}
}
示例5: api_getConstituency_postcode
function api_getConstituency_postcode($pc)
{
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (!validate_postcode($pc)) {
api_error('Invalid postcode');
return;
}
$constituency = postcode_to_constituency($pc, true);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
return;
}
if (!$constituency) {
api_error('Unknown postcode');
return;
}
return _api_getConstituency_name($constituency);
}
示例6: api_getconstituency_postcode
function api_getconstituency_postcode($pc) {
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (get_http_var('future')) {
$new_areas = mapit_get_voting_areas($pc, 13); # Magic number 13
if (is_object($new_areas)) { # rabx_is_error throws Notice
api_error('Unknown postcode, or problem with lookup');
} elseif (!isset($new_areas['WMC'])) {
api_error('Unknown postcode, or problem with lookup');
} else {
$new_info = mapit_get_voting_area_info($new_areas['WMC']);
$output['name'] = $new_info['name'];
api_output($output);
}
} else {
if (validate_postcode($pc)) {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
} elseif ($constituency) {
$db = new ParlDB;
$q = $db->query("select constituency, data_key, data_value from consinfo
where constituency = '" . mysql_real_escape_string($constituency) . "'");
if ($q->rows()) {
for ($i=0; $i<$q->rows(); $i++) {
$data_key = $q->field($i, 'data_key');
$output[$data_key] = $q->field($i, 'data_value');
}
ksort($output);
}
$output['name'] = $constituency;
api_output($output);
} else {
api_error('Unknown postcode');
}
} else {
api_error('Invalid postcode');
}
}
}
示例7: api_getconstituency_postcode
function api_getconstituency_postcode($pc)
{
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (!validate_postcode($pc)) {
api_error('Invalid postcode');
return;
}
if (get_http_var('future')) {
$xml = simplexml_load_string(file_get_contents(POSTCODE_API_URL . urlencode($pc)));
if (!$xml || $xml->error) {
api_error('Unknown postcode, or problem with lookup');
return;
}
$output['name'] = iconv('utf-8', 'iso-8859-1//TRANSLIT', (string) $xml->future_constituency);
api_output($output);
} else {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
api_error('Connection timed out');
return;
}
if (!$constituency) {
api_error('Unknown postcode');
return;
}
$db = new ParlDB();
$q = $db->query("select constituency, data_key, data_value from consinfo\n where constituency = '" . mysql_real_escape_string($constituency) . "'");
if ($q->rows()) {
for ($i = 0; $i < $q->rows(); $i++) {
$data_key = $q->field($i, 'data_key');
$output[$data_key] = $q->field($i, 'data_value');
}
ksort($output);
}
$output['name'] = $constituency;
api_output($output);
}
}
示例8: postcode_to_person_id
function postcode_to_person_id($postcode)
{
twfy_debug('MP', "postcode_to_person_id converting postcode to person");
$constituency = strtolower(postcode_to_constituency($postcode));
return $this->constituency_to_person_id($constituency);
}
示例9: search_constituencies_by_query
function search_constituencies_by_query($searchterm)
{
if (validate_postcode($searchterm)) {
// Looks like a postcode - can we find the constituency?
$constituency = postcode_to_constituency($searchterm);
if ($constituency) {
return array(array($constituency), true);
}
}
// No luck so far - let's see if they're searching for a constituency.
$try = strtolower($searchterm);
$query = "select distinct\n (select name from constituency where cons_id = o.cons_id and main_name) as name\n from constituency AS o where name like :try\n and from_date <= date(now()) and date(now()) <= to_date";
$db = new ParlDB();
$q = $db->query($query, array(':try' => '%' . $try . '%'));
$constituencies = array();
for ($n = 0; $n < $q->rows(); $n++) {
$constituencies[] = $q->field($n, 'name');
}
return array($constituencies, false);
}
示例10: find_constituency
function find_constituency($args)
{
// We see if the user is searching for a postcode or constituency.
global $PAGE, $db;
if ($args['s'] != '') {
$searchterm = $args['s'];
} else {
$PAGE->error_message('No search string');
return false;
}
$constituencies = array();
$constituency = '';
$validpostcode = false;
if (validate_postcode($searchterm)) {
// Looks like a postcode - can we find the constituency?
$constituencies = postcode_to_constituency($searchterm);
if ($constituencies == '') {
$constituencies = array();
} else {
$validpostcode = true;
}
if (!is_array($constituencies)) {
$constituencies = array($constituencies);
}
}
if ($constituencies == array() && $searchterm) {
// No luck so far - let's see if they're searching for a constituency.
$try = strtolower($searchterm);
if (normalise_constituency_name($try)) {
$constituency = normalise_constituency_name($try);
} else {
$query = "select distinct\n (select name from constituency where cons_id = o.cons_id and main_name) as name \n from constituency AS o where name like '%" . mysql_real_escape_string($try) . "%'\n and from_date <= date(now()) and date(now()) <= to_date";
$q = $db->query($query);
for ($n = 0; $n < $q->rows(); $n++) {
$constituencies[] = $q->field($n, 'name');
}
}
}
if (count($constituencies) == 1) {
$constituency = $constituencies[0];
}
if ($constituency != '') {
// Got a match, display....
$MEMBER = new MEMBER(array('constituency' => $constituency));
$URL = new URL('mp');
if ($MEMBER->valid) {
$URL->insert(array('m' => $MEMBER->member_id()));
print '<h3>MP for ' . preg_replace("#{$searchterm}#i", '<span class="hi">$0</span>', $constituency);
if ($validpostcode) {
// Display the postcode the user searched for.
print ' (' . htmlentities(strtoupper($args['s'])) . ')';
}
?>
</h3>
<p><a href="<?php
echo $URL->generate();
?>
"><strong><?php
echo htmlentities($MEMBER->first_name()) . ' ' . htmlentities($MEMBER->last_name());
?>
</strong></a> (<?php
echo $MEMBER->party();
?>
)</p>
<?php
}
} elseif (count($constituencies)) {
print "<h3>MPs in constituencies matching '" . htmlentities($searchterm) . "'</h3><ul>";
foreach ($constituencies as $constituency) {
$MEMBER = new MEMBER(array('constituency' => $constituency));
$URL = new URL('mp');
if ($MEMBER->valid) {
$URL->insert(array('m' => $MEMBER->member_id()));
}
print '<li><a href="' . $URL->generate() . '"><strong>' . htmlentities($MEMBER->first_name()) . ' ' . htmlentities($MEMBER->last_name()) . '</strong></a> (' . preg_replace("#{$searchterm}#i", '<span class="hi">$0</span>', $constituency) . ', ' . $MEMBER->party() . ')</li>';
}
print '</ul>';
}
}
示例11: preg_replace
<?php
# Given a postcode, return a person ID
include_once 'min-init.php';
include_once INCLUDESPATH . 'easyparliament/member.php';
$pc = $_GET['pc'];
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (validate_postcode($pc)) {
$constituency = postcode_to_constituency($pc);
if ($constituency == 'CONNECTION_TIMED_OUT') {
error('Connection timed out');
} elseif ($constituency) {
$pid = get_person_id($constituency);
echo 'pid,', $pid;
} else {
error('Unknown postcode');
}
} else {
error('Invalid postcode');
}
function error($s)
{
echo 'error,', $s;
}
function get_person_id($c)
{
$db = new ParlDB();
if ($c == '') {
return false;
}
if ($c == 'Orkney ') {
示例12: create_map_filename
?>
<h2>General election constituency boundaries</h2>
<div id="boundaries">
<?
function create_map_filename($c) {
$c = str_replace(array(',', '(', ')', "'"), '', $c);
$c = str_replace('&', 'and', $c);
$c = str_replace("\xf4", 'o', $c);
$c = rawurlencode(strtolower($c));
return $c;
}
$pc = get_http_var('pc');
if ($pc) {
$current = postcode_to_constituency($pc);
$current_disp = str_replace('&', 'and', $current);
if ($current == "connection_timed_out") {
print "Sorry, we couldn't check your postcode right now, as our postcode lookup server is under quite a lot of load.";
} elseif ($current == "") {
print "Sorry, ".htmlentities($pc) ." isn't a known postcode";
}
$map_url_current = create_map_filename($current);
$new_areas = mapit_get_voting_areas($pc, 13); # Magic number 13
if (isset($new_areas['WMC'])) {
$new_info = mapit_get_voting_area_info($new_areas['WMC']);
$new = $new_info['name'];
$map_url_new = create_map_filename($new);
}
示例13: get_http_var
<?php
include_once "../../includes/easyparliament/init.php";
include_once INCLUDESPATH . "easyparliament/member.php";
include_once INCLUDESPATH . "postcode.inc";
$pc = get_http_var('pc');
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (!$pc) {
exit;
}
if (validate_postcode($pc)) {
$constituency = strtolower(postcode_to_constituency($pc));
if ($constituency == "CONNECTION_TIMED_OUT") {
$errors['pc'] = "Sorry, we couldn't check your postcode right now. Please use the 'All Mps' link above to browse MPs";
} elseif ($constituency == "") {
$errors['pc'] = "Sorry, " . htmlentities($pc) . " isn't a known postcode";
twfy_debug('MP', "Can't display an MP, as submitted postcode didn't match a constituency");
} else {
$MEMBER = new MEMBER(array('constituency' => $constituency));
if ($MEMBER->person_id()) {
// This will cookie the postcode.
$THEUSER->set_postcode_cookie($pc);
$THEUSER->set_constituency_cookie($constituency);
}
if ($MEMBER->person_id()) {
header('Location: http://' . DOMAIN . '/rss/mp/' . $MEMBER->person_id() . '.rdf');
}
}
} else {
$errors['pc'] = "Sorry, " . htmlentities($pc) . " isn't a valid postcode";
twfy_debug('MP', "Can't display an MP because the submitted postcode wasn't of a valid form.");
示例14: testBrokenPostcodeToConstituency
/**
* Test converting a broken postcode to a constituency, make sure we get an empty string
*/
public function testBrokenPostcodeToConstituency()
{
$this->assertEquals('', postcode_to_constituency('ZZ00 ABC'));
}
示例15: set_users_mp
function set_users_mp()
{
// Is this MP THEUSER's MP?
global $THEUSER;
if (is_object($THEUSER) && $THEUSER->postcode_is_set() && $this->current_member(1)) {
$pc = $THEUSER->postcode();
twfy_debug('MP', "set_users_mp converting postcode to person");
$constituency = strtolower(postcode_to_constituency($pc));
if ($constituency == strtolower($this->constituency())) {
$this->the_users_mp = true;
}
}
}