本文整理汇总了PHP中str::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP str::parse方法的具体用法?PHP str::parse怎么用?PHP str::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::parse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct($uri = false)
{
// set the defaults
$this->path = new uriPath();
$this->params = new uriParams();
$this->query = new uriQuery(str::parse(server::get('query_string'), 'query'));
$this->extension = false;
$this->raw = $this->raw($uri);
$this->url = url(ltrim($this->raw, '/'));
// crawl the uri and get all elements
$this->crawl();
}
示例2: parse
function parse($result, $format = 'plain')
{
switch ($format) {
case 'xml':
case 'json':
case 'php':
$result = str::parse($result, $format);
return is_array($result) ? $result : false;
break;
default:
return $result;
break;
}
}
示例3: latest_post
public static function latest_post()
{
$cache = kirby()->cache()->get('facebook.latest.post');
if (!is_null($cache)) {
return response::json($cache);
}
$response = remote::get(url::build(array('scheme' => static::$graph_scheme, 'host' => static::$graph_host, 'fragments' => array(c::get('facebook.id'), 'posts'), 'query' => array('access_token' => c::get('facebook.accesstoken'), 'limit' => 1))));
if ($response->content) {
// parse json string
$data = str::parse($response->content)['data'][0];
$return = array('text' => $data['message'], 'picture' => $data['picture'], 'timestamp' => strtotime($data['updated_time']), 'time_formatted' => strftime('%d. %B %G', strtotime($data['updated_time'])), 'link' => $data['link']);
// set cache for 10 minutes
kirby()->cache()->set('facebook.latest.post', $return, 10);
} else {
return false;
}
return $return;
}
示例4: tweets
function tweets($username, $params = array())
{
$defaults = array('limit' => 10, 'cache' => true, 'refresh' => 60 * 20);
// add the username to the defaults array
$defaults['username'] = $username;
$options = array_merge($defaults, $params);
// check the cache dir
$cacheDir = c::get('root.cache') . '/tweets';
dir::make($cacheDir);
// disable the cache if adding the cache dir failed
if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
$options['cache'] = false;
}
// sanitize the limit
if ($options['limit'] > 200) {
$options['limit'] = 200;
}
// generate a unique cache ID
$cacheID = 'tweets/tweets.' . md5($options['username']) . '.' . $options['limit'] . '.php';
if ($options['cache']) {
$cache = cache::modified($cacheID) < time() - $options['refresh'] ? false : cache::get($cacheID);
} else {
$cache = false;
}
if (!empty($cache)) {
return $cache;
}
$url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $options['username'] . '&count=' . $options['limit'];
$json = @file_get_contents($url);
$data = str::parse($json);
if (!$data) {
return false;
}
$result = array();
foreach ($data as $tweet) {
$user = $tweet['user'];
$result[] = new tweet(array('url' => 'http://twitter.com/' . $options['username'] . '/status/' . $tweet['id_str'], 'text' => $tweet['text'], 'date' => strtotime($tweet['created_at']), 'source' => $tweet['source'], 'user' => new obj(array('name' => $user['name'], 'bio' => $user['description'], 'username' => $user['screen_name'], 'url' => 'http://twitter.com/' . $user['screen_name'], 'image' => 'http://twitter.com/api/users/profile_image/' . $user['screen_name'], 'following' => $user['friends_count'], 'followers' => $user['followers_count']))));
}
$result = new obj($result);
if ($options['cache']) {
cache::set($cacheID, $result);
}
return $result;
}
示例5: read
/**
* Reads the file content and parses it
*
* @param string $format
* @return mixed
*/
public function read($format = null)
{
return str::parse($this->content(), $format);
}
示例6: read
/**
* Reads the content of a file
*
* @param string $file The path for the file
* @param mixed $parse if set to true, parse the result with the passed method. See: "str::parse()" for more info about available methods.
* @return mixed
*/
static function read($file, $parse = false)
{
$content = @file_get_contents($file);
return $parse ? str::parse($content, $parse) : $content;
}
示例7: testParse
function testParse()
{
$this->assertEqual(str::parse('{"test":"cool","super":"genious"}'), array('test' => 'cool', 'super' => 'genious'));
$this->assertEqual(str::parse('<xml><entries><cool>nice</cool></entries></xml>', 'xml'), array('entries' => array('cool' => 'nice')));
}