function httprl_pr in HTTP Parallel Request & Threading Library 7
Same name and namespace in other branches
- 6 httprl.module \httprl_pr()
Pretty print data.
Parameters
string $input: Data In.
Return value
string Human readable HTML version of the data.
1 call to httprl_pr()
- httprl_requirements in ./
httprl.install - Implements hook_requirements().
6 string references to 'httprl_pr'
- httprl.examples.php in examples/
httprl.examples.php - HTTP Parallel Request Library code examples.
- httprl_parse_data in ./
httprl.module - Extract the header and meta data from the http data stream.
- httprl_parse_url in ./
httprl.module - Run parse_url and handle any errors.
- httprl_send_request in ./
httprl.module - Perform many HTTP requests.
- httprl_set_socket in ./
httprl.module - Create the TCP/SSL socket connection string.
File
- ./
httprl.module, line 2873 - HTTP Parallel Request Library module.
Code
function httprl_pr($input) {
$output_plain_text = FALSE;
if (strpos(implode("\n", array_map('strtolower', headers_list())), 'content-type: text/plain') !== FALSE || function_exists('drupal_is_cli') && drupal_is_cli()) {
$output_plain_text = TRUE;
}
$old_setting = ini_set('mbstring.substitute_character', '"none"');
// Get extra arguments passed in.
$input = func_get_args();
// If bool or strlen = 0 use var_export on that variable.
$data = httprl_print_empty($input, 0, $output_plain_text);
// Merge into base array if only one argument passed in.
if (count($data) == 1) {
$data = array_pop($data);
}
// Print_r the input.
$output = print_r($data, TRUE);
// Remove non UTF-8 Characters.
$encoded = FALSE;
if (function_exists('mb_convert_encoding')) {
$track_errors = ini_set('track_errors', '1');
$php_errormsg = '';
$translated = @mb_convert_encoding($output, 'UTF-8', 'auto');
if (empty($php_errormsg)) {
$encoded = TRUE;
}
$php_errormsg = '';
ini_set('track_errors', $track_errors);
}
if (!$encoded) {
$translated = @iconv('utf-8', 'utf-8//TRANSLIT//IGNORE', $output);
}
// Convert html entities.
$options = ENT_QUOTES;
if (defined('ENT_SUBSTITUTE')) {
$options = ENT_QUOTES | ENT_SUBSTITUTE;
}
elseif (defined('ENT_IGNORE')) {
$options = ENT_QUOTES | ENT_IGNORE;
}
$translated = htmlentities($translated, $options, 'UTF-8');
// Make sure the UTF-8 translation didn't kill the output.
$original_size = strlen($output);
$translated_size = strlen($translated);
$ratio = 0;
if ($original_size != 0) {
$ratio = ($original_size - $translated_size) / $original_size;
}
// Decide to use the original output or the translated one.
if (!empty($translated_size) && !empty($ratio) && $ratio < 0.5 && !$output_plain_text) {
$html_output = TRUE;
$output = $translated;
}
else {
if (!$output_plain_text) {
$output = str_replace(array(
'<',
'>',
), array(
'<',
'>',
), $output);
}
$output = "<pre>\n" . $output . "\n</pre>";
}
// Remove extra new lines.
$output = array_filter(explode("\n", $output), 'strlen');
// Whitespace compression.
foreach ($output as $key => $value) {
if (str_replace(' ', '', $value) == "(") {
$output[$key - 1] .= ' (';
unset($output[$key]);
}
}
// Replace whitespace with html markup.
$output = implode("\n", $output);
if (!empty($html_output)) {
$output = str_replace(' ', ' ', nl2br($output)) . '<br />';
}
else {
$output .= "\n";
}
ini_set('mbstring.substitute_character', $old_setting);
return $output;
}