本文整理汇总了PHP中prettyPrint函数的典型用法代码示例。如果您正苦于以下问题:PHP prettyPrint函数的具体用法?PHP prettyPrint怎么用?PHP prettyPrint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prettyPrint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dwbn_get_page
function dwbn_get_page($token, $page_uri)
{
//Bind global variables
global $oauth2_host;
//Get full uri
$uri = "https://" . $oauth2_host . $page_uri;
//Connect via curl
$ch = curl_init($uri);
//Disable sertificates check for HTTPS
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//Show or not recieve header
curl_setopt($ch, CURLOPT_HEADER, false);
//Show or not sent header - will be presented by curl_getinfo()
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
//Header is here
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: ' . $oauth2_host, "Authorization: Bearer " . $token));
//Return result to variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Exec curl command
$answer_json = curl_exec($ch);
//Prepare JSON to show
$answer_json_pretty = prettyPrint($answer_json);
//Put info into variable
$curl_getinfo = curl_getinfo($ch);
//Close curl connection
curl_close($ch);
//Ruturn
return array('curl_getinfo' => $curl_getinfo, 'answer_json' => $answer_json, 'answer_json_pretty' => $answer_json_pretty);
}
示例2: dwbn_get_page
function dwbn_get_page($token, $page_uri)
{
//Bind global variables
global $oauth2_host;
//Get full uri
$uri = "https://" . $oauth2_host . $page_uri;
//Connect using Google App Engine URL Fetch service
$context = ['http' => ['method' => 'GET', 'header' => "Host: {$oauth2_host}\r\n" . "Authorization: Bearer " . $token . "\r\n"]];
$context = stream_context_create($context);
//Get answer from DWBN
$answer_json = file_get_contents($uri, false, $context);
//Prepare JSON to show
$answer_json_pretty = prettyPrint($answer_json);
//Ruturn
return array('answer_json' => $answer_json, 'answer_json_pretty' => $answer_json_pretty);
}
示例3: exportSongs
function exportSongs()
{
$db_connection = new mysqli('stardock.cs.virginia.edu', 'cs4750ams5daa', 'music', 'cs4750ams5da');
if (mysqli_connect_errno()) {
echo "Connection Error!";
return;
}
/* header('Content-type: text/xml');
$data = '<?xml version="1.0" encoding="utf-8"?>';
$data .= "<ReturnType><Data>Here is some data</Data></ReturnType>";
echo "$data"; */
$var = array();
$sql = "SELECT * FROM Songs";
$result = mysqli_query($db_connection, $sql);
while ($obj = mysqli_fetch_object($result)) {
$var[] = $obj;
}
header('Content-Type: application/json; charset=utf-8');
$jsonStr = json_encode($var);
echo '{"Songs":' . prettyPrint($jsonStr) . '}';
//echo $jsonStr;
}
示例4: prettyPrint
// Update an urban word that does not exist
// Throws an exception - Urban Word not found
//$urbanWordsManager->updateUrbanWord("TGIF", "Thank God It's Free", "OMG, TGIF");
echo '<h4>Updated Urban Word</h4>';
prettyPrint($updatedUrbanWord);
// Delete an Urban Word
$urbanWordsManager->deleteUrbanWord($slang3);
// Delete an Urban Word that does not exist
// Throws an exception
// $urbanWordsManager->deleteUrbanWord("Ganga");
echo '<h4>Result after deleting one of the Urban Words</h4>';
prettyPrint(UrbanWordsManager::$data);
// This section tests the WordsGroup Class
$sentence = "let us pretend Marhsal Mathers never picked up a pen, let us pretend things would have been no different, pretend he procrastinated had no motivation, pretend he just made excuses that were so paper thin.";
// The group function groups the words in the given
// statement into an associative array
$grouped = WordsGroup::group($sentence);
echo '<h3>Grouped Words Example</h3>';
echo '<h5>Original Sentence</h5>';
echo $sentence;
echo '<h5>Grouped</h5>';
prettyPrint($grouped);
/**
* Hepler function to pretty print the data variables
*/
function prettyPrint($array)
{
echo '<pre>';
print_r((array) $array);
echo '</pre>';
}
示例5: apiReturnError
} else {
if ($group_id) {
// Attempt to load action permits for the specified group.
if (!($results = loadGroupActionPermits($group_id))) {
apiReturnError($ajax, getReferralPage());
}
} else {
if ($all == "users") {
// Attempt to load action permits for all users
if (!($results = loadUserActionPermits("all"))) {
apiReturnError($ajax, getReferralPage());
}
} else {
if ($all == "groups") {
// Attempt to load action permits for all groups
if (!($results = loadGroupActionPermits("all"))) {
apiReturnError($ajax, getReferralPage());
}
} else {
addAlert("danger", "user_id, group_id, or all must be specified.");
apiReturnError($ajax, getReferralPage());
}
}
}
}
restore_error_handler();
if ($pretty) {
echo prettyPrint(json_encode($results, JSON_PRETTY_PRINT));
} else {
echo json_encode($results);
}
示例6: str_repeat
}
}
}
if ($new_line_level !== NULL) {
$result .= "\n" . str_repeat("\t", $new_line_level);
}
$result .= $char . $post;
}
return $result;
}
/* eat question mark and go from there */
$qs = $_SERVER['QUERY_STRING'];
if ($qs[0] == '?') {
$qs = substr($qs, 1);
}
switch ($qs) {
case 'ip':
_h_json();
echo prettyPrint(json_encode($_SERVER['REMOTE_ADDR']));
return true;
case 'headers':
_h_json();
$headers = apache_request_headers();
echo prettyPrint(json_encode($headers));
return true;
default:
define('C64LEGIT', true);
return include 'redirector.php';
}
//unhandled
return false;
示例7: prettyPrint
<?php
$style = new \Drupal\livesource\ArtistStyle(26);
$eventFormat = new \Drupal\livesource\EventFormatter($style);
$result = $eventFormat->setArtist()->formattedResults();
print prettyPrint(json_encode($result)) . "\n";
function prettyPrint($json)
{
$result = '';
$level = 0;
$in_quotes = false;
$in_escape = false;
$ends_line_level = NULL;
$json_length = strlen($json);
for ($i = 0; $i < $json_length; $i++) {
$char = $json[$i];
$new_line_level = NULL;
$post = "";
if ($ends_line_level !== NULL) {
$new_line_level = $ends_line_level;
$ends_line_level = NULL;
}
if ($in_escape) {
$in_escape = false;
} else {
if ($char === '"') {
$in_quotes = !$in_quotes;
} else {
if (!$in_quotes) {
switch ($char) {
case '}':
示例8: str_replace
}
$result .= $char . $post;
$prev_char = $char;
}
return $result;
}
?>
<form action="<?php
echo Route::url('index.php?option=' . $this->option);
?>
" method="post" name="adminForm" id="adminForm">
<table class="adminlist">
<tbody>
<tr>
<td>
<pre>
<?php
echo str_replace("\t", ' ', prettyPrint(json_encode($this->output)));
?>
</pre>
</td>
</tr>
</tbody>
</table>
<?php
echo Html::input('token');
?>
</form>
示例9: set_config
/**
* Set miner config.
*
* @param array $data
* The orig data from phpminer. (Optional, default = array())
*/
public function set_config($data = array())
{
// Get current cgminer config.
$conf = json_decode(file_get_contents($this->config['cgminer_config_path']), true);
// When the value is empty, we have to remove it from the cgminer config.
if (empty($data['value'])) {
if (isset($conf[$data['key']])) {
unset($conf[$data['key']]);
}
} else {
// When we have a gpu key, then we have a multi value field. This means values can be seperated by , (comma).
if (isset($data['gpu'])) {
// If config key doesn't exist yet, create it.
if (!isset($conf[$data['key']])) {
$conf[$data['key']] = '';
}
// Get current config values per gpu.
$config_values = explode(",", $conf[$data['key']]);
// If there are no config values yet, create an empty array.
if (empty($config_values)) {
$config_values = array();
}
// Get the provided values, which should be set per gpu.
$device_values = array();
if (isset($data['current_values']) && !empty($data['current_values'])) {
$device_values = explode(",", $data['current_values']);
if (empty($device_values)) {
$device_values = array();
}
}
// Get the device count, so we can create the correct comma seperated value.
$device_count = $data['devices'];
// Loop through each device.
for ($i = 0; $i < $device_count; $i++) {
// If the config key does not exist, fill it with 0.
if (!isset($config_values[$i])) {
$config_values[$i] = !isset($device_values[$i]) ? 0 : $device_values[$i];
}
}
// Set the given gpu value.
$config_values[$data['gpu']] = $data['value'];
// Get the end result of the config key with all gpu values.
$conf[$data['key']] = implode(",", $config_values);
} else {
// Parse "true" to boolean true
if ($data['value'] === 'true') {
$data['value'] = true;
}
// Parse "false" to boolean false
if ($data['value'] === 'false') {
$data['value'] = false;
}
// Set new config key value.
$conf[$data['key']] = $data['value'];
}
}
// Try to store the new config.
if (file_put_contents($this->config['cgminer_config_path'], str_replace('\\/', '/', prettyPrint(json_encode($conf)))) === false) {
throw new Exception('Could not write config file');
}
}
示例10: mysql_query
<table align="center">
<tr>
<th>Event ID</th>
<th>Payload</th>
</tr>
<?php
$sql_query = "SELECT * FROM events";
$result_set = mysql_query($sql_query);
while ($row = mysql_fetch_row($result_set)) {
?>
<tr>
<td><?php
echo $row[0];
?>
</td>
<td><?php
echo prettyPrint($row[1]);
?>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</center>
</body>
</html>
示例11: ParseMap
//.........这里部分代码省略.........
}
if (!is_array($gtdata['controlpoint'])) {
$map['gametypes'][$gtname]['controlpoint'] = array($gtdata['controlpoint']);
}
$cps = $map['gametypes'][$gtname]['controlpoint'];
//Process any entities in the gamedata text file.
$entlist = array();
if (!isset($gtdata[$entities_key])) {
continue;
}
foreach ($gtdata[$entities_key] as $entname => $entity) {
//var_dump($entname,$entity);
//KV reader now handles multiple like-named resources by creating a numerically indexed array
//When doing that, the is_multiple_array flag is set
if (isset($entity['is_multiple_array'])) {
//If multiple items, send each to the array
foreach ($entity as $subent) {
if (is_array($subent)) {
$subent['classname'] = $entname;
$entlist[] = CreatePoint($subent, $map);
}
}
} else {
//Otherwise, pack the single item
$entity['classname'] = $entname;
$entlist[] = CreatePoint($entity, $map);
}
}
//Process all gamedata entities that are referenced by the controlpoints list
foreach ($entlist as $id => $entity) {
if (!isset($entity['pos_name'])) {
continue;
}
$cp = $entity['pos_name'];
//(isset($entity['controlpoint'])) ? $entity['controlpoint'] : $entity['targetname'];
foreach ($entity as $key => $val) {
if (!isset($map['gametypes'][$gtname][$points_key][$cp][$key]) || @$entity['targetname'] == $cp && $key != 'classname' || @$entity['targetname'] != $cp && $key == 'classname') {
$map['gametypes'][$gtname][$points_key][$cp][$key] = $val;
}
}
}
/*
//chr 65 is uppercase A. This lets me 'increment' letters
$chr = 65;
// Loop through control points and name them
foreach ($cps as $idx => $cp) {
$cpname = chr($chr);
unset($map['gametypes'][$gtname]['controlpoint'][$idx]);
$map['gametypes'][$gtname]['controlpoint'][$cpname] = (isset($map['gametypes'][$gtname][$points_key][$cp])) ? $map['gametypes'][$gtname][$points_key][$cp] : $map[$points_key][$cp];
//Set point name to the letter of the objective
//$map['gametypes'][$gtname][$points_key][$cp]
$map['gametypes'][$gtname]['controlpoint'][$cpname]['pos_name'] = $cpname;
if (isset($gtdata['attackingteam'])) {
$map['gametypes'][$gtname]['controlpoint'][$cpname]['pos_team'] = ($gtdata['attackingteam'] == 'security') ? 3 : 2;
}
$chr++;
}
*/
//Bullshit to add teams to points, Skirmish game logic does it instead of saving it in the maps.
if ($gtname == 'skirmish') {
$map['gametypes'][$gtname]['controlpoint']['B']['pos_team'] = 2;
$map['gametypes'][$gtname]['controlpoint']['D']['pos_team'] = 3;
}
//Same deal for Firefight
if ($gtname == 'firefight') {
$map['gametypes'][$gtname]['controlpoint']['A']['pos_team'] = 2;
$map['gametypes'][$gtname]['controlpoint']['C']['pos_team'] = 3;
}
/*
//Parse spawn zones. This is tricky because there will usually be two zones with the same targetname
// but different teamnum. This is to allow spawning to move as the game changes I believe.
if (isset($gtdata['spawnzones'])) {
foreach ($gtdata['spawnzones'] as $szid => $szname) {
if (is_numeric($szid)) {
unset($map['gametypes'][$gtname]['spawnzones'][$szid]);
$sz = array();
foreach (array('_team2','_team3') as $suffix) {
if (isset($map[$points_key]["{$szname}{$suffix}"]))
$sz["{$szname}{$suffix}"] = $map[$points_key]["{$szname}{$suffix}"];
}
$map['gametypes'][$gtname]['spawnzones'][$szname] = $sz;
}
}
}
// Remove the points and entities sections from the finished data structure. We no longer need them.
if (@is_array($map['gametypes'][$gtname][$points_key])) {
unset($map['gametypes'][$gtname][$points_key]);
}
if (@is_array($map['gametypes'][$gtname][$entities_key])) {
unset($map['gametypes'][$gtname][$entities_key]);
}
*/
//echo "done parse gametypes\n";
}
recur_ksort($map);
$json = prettyPrint(json_encode($map));
file_put_contents($dstfile, $json);
echo "OK: Parsed {$mapname}{$linebreak}";
// var_dump(array_merge_recursive($srcfiles,$map['source_files']));
}
示例12: cURL
function cURL($jsonString)
{
$protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
$options = array("url" => $protocol . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/../public/index.php");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $options["url"]);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($jsonString)));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$res = prettyPrint($result, "API Response : ");
echo "<br/><br/>";
echo $res;
}
示例13: GetServer
function GetServer($host, $port, $region = '', $cacheonly = 1, $forcerefresh = 0)
{
global $paths, $columns, $server_file_maxage, $tag_values;
$ip = gethostbyname($host);
$server = array('region' => $region, 'info' => array('serverName' => "<b>[LOADING]</b>{$ip}:{$port}", 'mapName' => '', 'numberOfPlayers' => 0, 'maxPlayers' => 0, 'serverTags' => ''), 'tags' => array('g' => '', 'p' => '', 't' => '', 'pure' => ''), 'ipAddress' => $ip, 'port' => $port);
/*
foreach ($columns as $column) {
if (!isset($server[$column])) {
$server[$column] = '';
}
}
*/
$cache_file = "{$paths['servers']}/{$ip}_{$port}.json";
// Should we use the cache file?
if (file_exists($cache_file)) {
$get_cache = filemtime($cache_file) > time() - $server_file_maxage && !$forcerefresh;
if ($get_cache || $cacheonly) {
$cache = json_decode(file_get_contents($cache_file), TRUE);
$server = array_replace_recursive($server, $cache);
//var_dump($cache,$server);
//$server['updated'] = filemtime($cache_file);
// If server has an error, attempt new fetch
//$get_cache = (!isset($server['error']));
}
}
// If the cached data is not available or has been invalidated, refresh
if (!$cacheonly && (!$get_cache || $forcerefresh)) {
try {
$connection = new \SteamCondenser\Servers\SourceServer($ip, $port);
$connection->initialize();
// Collect data from Steam Condenser
$server['ping'] = $connection->getPing();
$server['players'] = $connection->getPlayers();
$server['rules'] = $connection->getRules();
$server['info'] = $connection->getServerInfo();
$tags = array_filter(explode(',', $server['info']['serverTags']));
foreach ($tags as $tag) {
$bits = explode(':', $tag, 2);
if (count($bits) == 2) {
$server['tags'][$bits[0]] = $tag_values[$bits[0]][$bits[1]] = $bits[1];
} else {
$server['tags'][$tag] = $tag_values[$tag] = "__";
}
}
$server['updated'] = time();
file_put_contents($cache_file, prettyPrint(json_encode($server)), LOCK_EX);
} catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n";
$server['error'] = $e->getMessage();
file_put_contents($cache_file, prettyPrint(json_encode($server)), LOCK_EX);
}
}
// Skip processing for servers with errors
if ($region) {
$server['region'] = $region;
}
return $server;
}
示例14: fgets
$line = fgets($file);
echo $line . "<br>";
}
fclose($file);
?>
</code></pre>
<p>Result:</p>
<pre><code class="language-json"><?php
$sample = explode(",", $response_json);
$sample = array_slice($sample, 0, 19);
$sample = implode(",", $sample);
$sample = str_replace("\\", "", $sample);
echo prettyPrint($sample);
?>
... </code></pre>
<p>If you want the result in standard php object, just decode it:</p>
<pre><code class="language-php">$response = json_decode( $response_json );
//Prints the first item's text:
echo $response->data[0]->text;</code></pre>
<h2>Notes</h2>
<h3>Authentication</h3>
示例15: json_encode_helper
function json_encode_helper($data, $pretty_print = FALSE)
{
$ret = json_encode((object) $data);
$ret = str_replace('\\/', '/', $ret);
if ($pretty_print) {
$ret = prettyPrint($ret);
}
return $ret;
}