Example #1
0
/**
 * 获取文章详情
 * @param type $id
 * @return type
 */
function getArticle($id)
{
    $obj = pickOne($id);
    $body_without_html = htmlToText($obj['body']);
    $obj['description'] = mb_substr($body_without_html, '0', 150, 'utf8');
    $obj['source'] = '绝想日记网';
    /* 设置文章属性 */
    if (!empty($obj['litpic'])) {
        $obj['flag'] = ',f,p';
    }
    if (rand(1, 3) == 2) {
        $obj['flag'] = ',c';
    }
    if (rand(1, 3) == 2) {
        $obj['flag'] = ',h';
    }
    if (rand(1, 3) == 2) {
        $obj['flag'] = ',s';
    }
    $obj['flag'] = ltrim($flag['flag'], ',');
    $obj['flag'] = explode(',', $flag);
    $obj['keywords'] = '随笔坞';
    $obj['qianbian'] = rand(0, 20);
    $obj['zhichi'] = rand(0, 300);
    $obj['zhaoma'] = rand(0, 70);
    $obj['gaoxiao'] = rand(0, 80);
    $obj['chedan'] = rand(0, 100);
    $obj['bujie'] = rand(0, 200);
    $obj['chijing'] = rand(0, 50);
    $obj['henbang'] = rand(0, 200);
    return $obj;
}
Example #2
0
// Loop through channel members
foreach ($data['channel']['members'] as $m) {
    // Get user data
    $userData = $Slack->call('users.info', array('user' => $m));
    // Check to see if the user is online before adding them to list of brewers
    $presence = $Slack->call('users.getPresence', array('user' => $m));
    $user = $userData['user'];
    // If there is an exclude, check to see if it matches a user real name (lowercase)
    // If it does not, add it to the $coffeeMakers array
    if ($presence['presence'] == 'active') {
        if ($exclude) {
            if (!(strpos(strtolower($user['real_name']), strtolower($exclude)) !== false)) {
                $coffeeMakers[] = $user;
            }
        } else {
            $coffeeMakers[] = $user;
        }
    }
}
// Shuffle shuffle shuffle the arrays
function pickOne($array)
{
    shuffle($array);
    return $array[mt_rand(0, count($array) - 1)];
}
// Get a random user from the array
$user = pickOne($coffeeMakers);
// SEND OUT THE JSON!! Enjoy your brew
header('Content-Type: application/json');
echo json_encode(array('text' => str_replace('{{USER}}', '<@' . $user['id'] . '>', pickOne($responses))));
<?php

function pickone($x, $y = "Pie")
{
    return $y;
}
$pi = 3.1416;
$simple_pi = (int) $pi;
$numeric = (double) "2.5x";
$pi = pickOne($pi);
print_r($pi);