本文整理汇总了PHP中json_format函数的典型用法代码示例。如果您正苦于以下问题:PHP json_format函数的具体用法?PHP json_format怎么用?PHP json_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了json_format函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 ')';
}
}
开发者ID:rdmpage,项目名称:phyloinformatics,代码行数:30,代码来源:get_hits.php
示例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);
}
开发者ID:hcopr,项目名称:Hubbub,代码行数:8,代码来源:lib.php
示例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));
}
开发者ID:navruzm,项目名称:navruz.net,代码行数:9,代码来源:Mongo_export.php
示例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);
}
开发者ID:GalAfik,项目名称:TimelineTweets,代码行数:14,代码来源:get_tweets.php
示例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 ')';
}
}
开发者ID:rdmpage,项目名称:biostor,代码行数:42,代码来源:api_utils.php
示例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;
}
}
开发者ID:rdmpage,项目名称:phyloinformatics,代码行数:41,代码来源:clusterstrings.php
示例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;
}
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:21,代码来源:config_current.php
示例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;
}
}
开发者ID:rdmpage,项目名称:phyloinformatics,代码行数:40,代码来源:specimenparser.php
示例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));
开发者ID:HeuristNetwork,项目名称:heurist,代码行数:30,代码来源:findSimilarRecords.php
示例10: toPrettyString
function toPrettyString()
{
return json_format($this->toString());
}
开发者ID:rodrigorm,项目名称:OFC,代码行数:4,代码来源:Chart.php
示例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);
}
开发者ID:xpressengine,项目名称:xpressengine,代码行数:15,代码来源:ComposerFileWriter.php
示例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;
开发者ID:rdmpage,项目名称:bioguid,代码行数:67,代码来源:openurl.php
示例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_");
开发者ID:beoutsports,项目名称:heurist-v3-1,代码行数:31,代码来源:saveURLasFile.php
示例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);
}
开发者ID:rdmpage,项目名称:bioguid,代码行数:11,代码来源:mendeleyoauth.php
示例15: jlog
function jlog($json)
{
if (!is_string($json)) {
$json = json_encode($json);
}
echo json_format($json) . "\n";
}
开发者ID:PizzaBrandon,项目名称:Nest-Extended,代码行数:7,代码来源:examples.php
示例16: construct_legacy_search
}
if (!@$_REQUEST['q'] || @$_REQUEST['ver'] && intval(@$_REQUEST['ver']) < SEARCH_VERSION) {
construct_legacy_search();
}
// migration path
if (!@$_REQUEST['q'] && !@$_REQUEST['s']) {
return;
}
// wwgd
if ($_REQUEST['w'] == 'B' || $_REQUEST['w'] == 'bookmark') {
$search_type = BOOKMARK;
} else {
$search_type = BOTH;
}
// all records
mysql_connection_select(DATABASE);
if (preg_match('/\\b_BROKEN_\\b/', $_REQUEST['q'])) {
$broken = 1;
$_REQUEST['q'] = preg_replace('/\\b_BROKEN_\\b/', '', $_REQUEST['q']);
}
$query = REQUEST_to_query("select rec_ID, bkm_ID ", $search_type);
if (@$broken) {
$query = str_replace(' where ', ' where (to_days(now()) - to_days(rec_URLLastVerified) >= 8) and ', $query);
}
$res = mysql_query($query);
$ids = array();
while ($row = mysql_fetch_assoc($res)) {
array_push($ids, array("recID" => $row["rec_ID"], "bkmk_id" => $row["bkm_ID"]));
}
print json_format($ids);
开发者ID:beoutsports,项目名称:heurist-v3-1,代码行数:30,代码来源:getRecordIDsForSearch.php
示例17: main
/**
* @brief Handle microcitation request
*
*/
function main()
{
global $config;
global $debug;
// If no query parameters
if (count($_GET) == 0) {
//display_form();
exit(0);
}
$callback = '';
if (isset($_GET['callback'])) {
$callback = $_GET['callback'];
}
$format = 'json';
$debug = false;
if (isset($_GET['debug'])) {
$debug = true;
}
$q = $_GET['q'];
$result->pages = matching_pages($q);
if (count($result->pages) == 0) {
if ($format == 'json') {
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
$_SERVER['REDIRECT_STATUS'] = 404;
echo 'Not found';
exit;
}
} else {
// Do we have any references for the pages?
$result->references = reference_from_page($result->pages);
}
// Candidate pages
if ($format == 'json') {
header("Content-type: text/plain; charset=utf-8\n\n");
if ($callback != '') {
echo $callback . '(';
}
echo json_format(json_encode($result));
if ($callback != '') {
echo ')';
}
}
}
开发者ID:rdmpage,项目名称:bioguid,代码行数:48,代码来源:m.php
示例18: mysql__update
if (array_key_exists($varNames[0], $_POST)) {
$updates[$colName] = $_POST[$varNames[0]];
}
}
mysql__update("usrBookmarks", "bkm_ID={$bkm_ID} and bkm_UGrpID={$usrID}", $updates);
$res = mysql_query("select " . join(", ", array_keys($updates)) . " from usrBookmarks where bkm_ID={$bkm_ID} and bkm_UGrpID={$usrID}");
if (mysql_num_rows($res) == 1) {
$dbVals = mysql_fetch_assoc($res);
$hVals = array();
foreach ($dbVals as $colName => $val) {
$hVals[$updatable[$colName][1]] = $val;
}
if ($tagString !== NULL) {
$hVals["tagString"] = $tagString;
}
print "(" . json_format($hVals) . ")";
} else {
if ($tagString !== NULL) {
print "({tagString: \"" . slash($tagString) . "\"})";
}
}
}
function doTagInsertion($bkm_ID)
{
global $usrID;
//translate bmkID to record IT
$res = mysql_query("select bkm_recID from usrBookmarks where bkm_ID={$bkm_ID}");
$rec_id = mysql_fetch_row($res);
$rec_id = $rec_id[0] ? $rec_id[0] : null;
if (!$rec_id) {
return "";
开发者ID:HeuristNetwork,项目名称:heurist,代码行数:31,代码来源:saveBookmarkData.php
示例19: header
* @version 3.1.0
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package Heurist academic knowledge management system
* @subpackage !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/
/**
* 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__) . "/../../search/getSearchResults.php";
$args = json_decode(@$_POST["data"] ? $_POST["data"] : base64_decode(@$_GET["data"]), true);
$result = loadSearch($args);
if (array_key_exists("records", $result)) {
// turn the associative array into the non-associative one HAPI expects
foreach ($result["records"] as $i => $record) {
$result["records"][$i] = array(@$record["rec_ID"], null, @$record["rec_RecTypeID"], @$record["rec_Title"], @$record["details"], @$record["rec_URL"], @$record["rec_ScratchPad"], @$record["rec_OwnerUGrpID"], @$record["rec_NonOwnerVisibility"], @$record["rec_URLLastVerified"], @$record["rec_URLErrorMessage"], @$record["rec_Added"], @$record["rec_Modified"], @$record["rec_AddedByUGrpID"], @$record["rec_Hash"], @$record["bkm_ID"], null, @$record["bkm_Rating"], null, null, @$record["tags"], @$record["wgTags"], @$record["notifies"], @$record["comments"]);
}
}
print json_format($result);
开发者ID:HeuristNetwork,项目名称:heurist,代码行数:30,代码来源:loadSearch.php
示例20: json_encode
<?php
require "pretty_print_json.php";
$model = $_REQUEST["sg"];
//pre processing the json before writing to file
//$modelTask["task"] = $task;
/*if(version_compare(PHP_VERSION, '5.4.0', '>=')){
$model = json_encode($completeModel, JSON_PRETTY_PRINT);
} else {
$model = json_encode($completeModel, 128);
}*/
try {
$modelArray = json_decode($model, true);
$completeModel = "{\"task\": {$model}}";
$model = json_format($completeModel);
// convert messy JSON to pretty JSON
} catch (Exception $e) {
echo "{ \"error\":\"" . ($e->e = getMessage() . "\"}");
// we need to log the error to the server log file
}
try {
$name = $modelArray["taskName"];
$name = str_replace(" ", "-", $name);
$name = "problems/" . $name . ".json";
//checking if the file name already exists
if (file_exists($name)) {
throw new Exception("File with same name already exist");
}
//writing to file
$file = fopen($name, "w");
fwrite($file, stripslashes($model));
开发者ID:vanlehn,项目名称:LaitsV3,代码行数:31,代码来源:publish_solution.php
注:本文中的json_format函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论