本文整理汇总了PHP中json_format函数的典型用法代码示例。如果您正苦于以下问题:PHP json_format函数的具体用法?PHP json_format怎么用?PHP json_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
function main()
{
$callback = '';
if (isset($_GET['callback'])) {
$callback = $_GET['callback'];
}
if (isset($_GET['rid'])) {
$rid = $_GET['rid'];
}
$accessions = array();
$xml_filename = 'tmp/' . $rid . '.xml';
$xml = file_get_contents($xml_filename);
$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
$xpath_query = "//Hit_accession";
$nodeCollection = $xpath->query($xpath_query);
foreach ($nodeCollection as $node) {
$accessions[] = $node->firstChild->nodeValue;
}
$ids = array_slice($accessions, 0, NumSequences);
$hits = fetch_sequences($ids);
if ($callback != '') {
echo $callback . '(';
}
echo json_format(json_encode($hits));
if ($callback != '') {
echo ')';
}
}
示例2: setConfigData
function setConfigData($cfg)
{
$tmplFile = '<? $GLOBALS[$cfgCategory] = json_decode(\''.json_format(json_encode($cfg)).'\', true); ?>';
$cfgFileName = 'conf/default.php';
@chmod('conf', 0777);
if(file_exists($cfgFileName)) unlink($cfgFileName);
WriteToFile($cfgFileName, $tmplFile);
}
示例3: export
public function export($var)
{
$var = $this->_formatVarAsJSON($var);
$string = json_encode($var);
foreach ($this->_jsonParams as $index => $value) {
$string = str_replace("\"" . $this->_param($index) . "\"", $value, $string);
}
return json_unicode_to_utf8(json_format($string));
}
示例4: writeFile
function writeFile($filename, $dir, $tweetData)
{
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
$filepath = "{$dir}/{$filename}";
$filtered_tweets = array_map(function ($tweet) {
$user = $tweet->{'user'};
return (object) array('userId' => $user->{'id'}, 'user' => $user->{'name'}, 'location' => $user->{'location'}, 'text' => $tweet->{'text'}, 'date' => $tweet->{'created_at'}, 'retweetCount' => $tweet->{'retweet_count'}, 'favoriteCount' => $tweet->{'favorite_count'});
}, json_decode($tweetData));
$fh = fopen($filepath, 'w');
fwrite($fh, json_format($filtered_tweets));
fclose($fh);
}
示例5: api_output
function api_output($obj, $callback)
{
$status = 404;
// $obj may be array (e.g., for citeproc)
if (is_array($obj)) {
if (isset($obj['status'])) {
$status = $obj['status'];
}
}
// $obj may be object
if (is_object($obj)) {
if (isset($obj->status)) {
$status = $obj->status;
}
}
switch ($status) {
case 303:
header('HTTP/1.1 404 See Other');
break;
case 404:
header('HTTP/1.1 404 Not Found');
break;
case 410:
header('HTTP/1.1 410 Gone');
break;
case 500:
header('HTTP/1.1 500 Internal Server Error');
break;
default:
break;
}
header("Content-type: text/plain");
header("Cache-control: max-age=3600");
if ($callback != '') {
echo $callback . '(';
}
//echo json_encode($obj, JSON_PRETTY_PRINT);
echo json_format(json_encode($obj));
if ($callback != '') {
echo ')';
}
}
示例6: find_clusters
function find_clusters($text, $format = 'json')
{
$obj = new stdclass();
$obj->text = $text;
$strings = explode("\n", trim($text));
$obj->result = cluster($strings);
switch ($format) {
case 'json':
echo json_format(json_encode($obj));
break;
case 'html':
default:
echo '<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css" title="text/css">
body {
font-family: sans-serif;
margin:20px;
}
</style>
<a href="clusterstrings.php">Home</a>
<title>Cluster strings</title>
</head>
<body>
<h1>Cluster strings results</h1>';
echo '<pre>';
echo $obj->result->graph;
echo '</pre>';
//echo str_replace("\n", '', $obj->result->graph);
$s = urlencode(str_replace("\n", '', $obj->result->graph));
echo '<img src="http://chart.googleapis.com/chart?cht=gv&chl=' . $s . '" />';
echo '<pre>';
print_r($obj->result->clusters);
echo '</pre>';
echo '</body>
</html>';
break;
}
}
示例7: dv_config_current
function dv_config_current()
{
global $com_name, $conf;
$base = $conf['dir_base'];
$db_id = Request::getString('db', false);
require_once JPATH_COMPONENT_SITE . DS . 'dv_config.php';
$dv_conf_file = $base . DS . $db_id . DS . 'applications/dataviewer/config.json';
$db_dv_conf = array();
if (file_exists($dv_conf_file)) {
$db_dv_conf = json_decode(file_get_contents($dv_conf_file), true);
if (!is_array($db_dv_conf)) {
$db_dv_conf = array();
}
if (isset($db_dv_conf['settings'])) {
$db_dv_conf['settings'] = array_merge($dv_conf['settings'], $db_dv_conf['settings']);
}
}
$dv_conf = array_merge($dv_conf, $db_dv_conf);
print json_format(json_encode($dv_conf));
exit;
}
示例8: find_specimens
function find_specimens($text, $format = 'json')
{
$obj = new stdclass();
$obj->text = $text;
$obj->codes = extract_specimen_codes($text);
switch ($format) {
case 'json':
$obj->text = html_entity_decode($obj->text, ENT_QUOTES, 'UTF-8');
echo json_format(json_encode($obj));
break;
case 'html':
default:
echo '<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css" title="text/css">
body {
font-family: sans-serif;
margin:20px;
}
</style>
<a href="specimenparser.php">Home</a>
<title>Specimen parser</title>
</head>
<body>
<h1>Specimen parser results</h1>
<h2>Specimen codes</h2>
<ul>';
foreach ($obj->codes as $code) {
echo '<li>' . $code . '</li>';
}
echo '</ul>
<h2>Input</h2>
<p>' . htmlentities($obj->text, ENT_QUOTES, 'UTF-8') . '</p>
</body>
</html>';
break;
}
}
示例9: header
/**
* filename, brief description, date of creation, by whom
* @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
* @link: http://HeuristNetwork.org
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @package Heurist academic knowledge management system
* @todo
**/
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
session_cache_limiter('no-cache');
define('SAVE_URI', 'disabled');
define('SEARCH_VERSION', 1);
require_once dirname(__FILE__) . "/../../common/connect/applyCredentials.php";
require_once dirname(__FILE__) . "/../../common/php/dbMySqlWrappers.php";
require_once dirname(__FILE__) . "/../../records/disambig/findFuzzyRecordMatches.php";
$data = json_decode(@$_POST["data"] ? $_POST["data"] : base64_decode(@$_GET["data"]), true);
$details = @$data["details"];
$types = @$data["types"];
$id = @$data["id"] ? $data["id"] : null;
$fuzziness = @$data["fuzziness"] ? $data["fuzziness"] : null;
if (!$details || !$types) {
print json_format(array("error" => "invalid arguments"));
return;
}
mysql_connection_select(DATABASE);
$matches = findFuzzyMatches($details, $types, $id, $fuzziness);
print json_format(array("matches" => $matches));
示例10: toPrettyString
function toPrettyString()
{
return json_format($this->toString());
}
示例11: write
/**
* save loaded data to plugin composer file
*
* @return void
*/
public function write()
{
$json = json_encode($this->data);
if (function_exists('json_format')) {
$json = json_format($json);
} else {
$json = \Composer\Json\JsonFormatter::format($json, true, true);
}
file_put_contents($this->path, $json);
}
示例12: main
//.........这里部分代码省略.........
echo '</pre>';
}
// Handle identifiers
if (isset($referent->url)) {
// BHL URL, for example if we have already mapped article to BHL
// in Zotero,
if (preg_match('/^http:\\/\\/(www\\.)?biodiversitylibrary.org\\/page\\/(?<pageid>[0-9]+)/', $referent->url, $matches)) {
//print_r($matches);
$PageID = $matches['pageid'];
$references = bhl_reference_from_pageid($PageID);
//print_r($references);
if (count($references) == 0) {
// We don't have an article for this PageID
$search_hit = bhl_score_page($PageID, $referent->title);
// Store
$id = db_store_article($referent, $PageID);
} else {
// Have a reference with this PageID already
// Will need to handle case where > 1 article on same page, e.g.
// http://www.biodiversitylibrary.org/page/3336598
$id = $references[0];
}
// Did we get a hit?
if ($id != 0) {
// We have this reference in our database
switch ($format) {
case 'json':
// Display object
$reference = db_retrieve_reference($id);
header("Content-type: text/plain; charset=utf-8\n\n");
if ($callback != '') {
echo $callback . '(';
}
echo json_format(json_encode($reference));
if ($callback != '') {
echo ')';
}
break;
case 'html':
default:
// Redirect to reference display
header('Location: ' . $config['web_root'] . 'reference/' . $id . "\n\n");
break;
}
exit;
}
}
}
// OK, we're not forcing a match to BHL, so do we have this article?
$id = db_find_article($referent);
//echo "<b>id=$id</b><br/>";
if ($id != 0) {
// We have this reference in our database
switch ($format) {
case 'json':
// Display object
$reference = db_retrieve_reference($id);
header("Content-type: text/plain; charset=utf-8\n\n");
if ($callback != '') {
echo $callback . '(';
}
echo json_format(json_encode($reference));
if ($callback != '') {
echo ')';
}
break;
示例13: generate_thumbnail
header("Location: ".HEURIST_BASE_URL."/#data=" . $val);
return "";
}
ob_start("outputAsRedirect");
if ($_POST["heurist-sessionid"] != $_COOKIE["heurist-sessionid"]) { // saw TODO: check that this is ok or should this be the database session?
// saveFile is only available through dispatcher.php, or if heurist-sessionid is known (presumably only our scripts will know this)
getError("unauthorised HAPI user");
}
}
*/
if (@$_REQUEST['url']) {
$sURL = $_REQUEST['url'];
//url to be thumbnailed
$res = generate_thumbnail($sURL, true);
print json_format($res);
exit;
}
//
// main function
//
function generate_thumbnail($sURL, $needConnect)
{
if (!is_logged_in()) {
return getError("no logged-in user");
}
$res = array();
//get picture from service
//"http://www.sitepoint.com/forums/image.php?u=106816&dateline=1312480118";
$remote_path = str_replace("[URL]", $sURL, WEBSITE_THUMBNAIL_SERVICE);
$heurist_path = tempnam(HEURIST_UPLOAD_DIR, "_temp_");
示例14: get
/**
* GET wrapper for oAuthRequest.
*/
function get($url, $parameters = array())
{
$response = $this->oAuthRequest($url, 'GET', $parameters);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
return json_format($response);
}
示例15: jlog
function jlog($json)
{
if (!is_string($json)) {
$json = json_encode($json);
}
echo json_format($json) . "\n";
}