Пример #1
0
function doConvert($text)
{
    global $convert;
    foreach ($convert as $unitRegex => $rules) {
        if (1 === preg_match('/^\\s*((\\d+(?:' . ALL_SEPARATORS . '\\d+)?)(\\s*)' . $unitRegex . ')\\s*$/ui', $text, $matches)) {
            // the rules for this conversion
            list($outputUnit, $factor, $spaceFlag) = $rules;
            // the matching input (e.g. '123.45 kg')
            $whole = $matches[1];
            // the number part (e.g. '123.45')
            $numberPart = $matches[2];
            /// the result
            $resultNumber = $numberPart * $factor;
            // output in yards if many feet
            if ($outputUnit == '\'' && $resultNumber > 50) {
                $outputUnit = 'yards';
                $resultNumber /= 3;
                $spaceFlag = 1;
            } else {
                if ($outputUnit == '°C') {
                    $resultNumber = ($resultNumber - 32) * 5 / 9;
                } else {
                    if ($outputUnit == '°F') {
                        $resultNumber = $resultNumber * 9 / 5 + 32;
                    }
                }
            }
            // the whitespace to output between number an unit. mirror input unless 'space' flag is set
            if ($spaceFlag === 0) {
                $space = '';
            } else {
                if ($spaceFlag === 1) {
                    $space = ' ';
                } else {
                    $space = $matches[3];
                }
            }
            return str_replace($whole, number_format($resultNumber, places($numberPart), DECIMAL_SEPARATOR, '') . $space . $outputUnit, $text);
        }
    }
    return NULL;
}
Пример #2
0
function places_sublist($listName)
{
    if ($_REQUEST['category'] == 'buildings') {
        $drill = new DrillNumeralAlpha($listName, "key");
    } else {
        $drill = new DrillAlphabeta($listName, "key");
    }
    return $drill->get_list(places());
}
Пример #3
0
require 'db_connect.php';
require 'neo_connect.php';
// Create Users in Neo4j from database records
$users = users();
foreach ($users as $user) {
    create_user_node($user);
}
// Create friendships in Neo4j from database records
$friendships = friendships();
foreach ($friendships as $friendship) {
    $user = user_by_id($friendship['user_id']);
    $friend = user_by_id($friendship['friend_id']);
    create_neo_friendship($user, $friend);
}
// Create place nodes
$places = places();
foreach ($places as $place) {
    create_place_node($place);
}
$user_db = user_by_id(64);
$place_db = place_by_id(5);
create_neo_list_entry($user_db, $place_db);
$user_db = user_by_id(65);
$place_db = place_by_id(6);
create_neo_list_entry($user_db, $place_db);
function create_user_node($properties)
{
    global $client, $user_name_index, $user_id_index;
    // only insert this node if we have not already seen it
    $index_entry = $user_id_index->findOne('dbid', $properties['id']);
    //print_r($index_entry);