curl stdout to highlight_string

To pipe standard output (stdout) from curl directly into PHP's highlight_string function in your terminal, pass the curl output into PHP using standard input (@-) for a quick and formatted display. [1]

Executing in the Terminal

Run the following command in your terminal. This captures the curl output, prefixes it with a PHP opening tag, and runs it through PHP's command-line parser to color-code it: [1, 2, 3]

B
curl -s https://api.github.com | php -r 'highlight_string("<?php\n" . file_get_contents("php://stdin") . "\n?>");'

Scripting with PHP

If you are writing this as part of a larger PHP script, use a local variable instead of file_get_contents:

php
// Capture curl stdout via execution
$ch = curl_init('https://api.github.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
// Syntax highlight the output
highlight_string("<?php\n" . $output . "\n?>");

If you want more:
What kind of output are you processing (JSON, HTML, plain text)?
Do you need to save this highlighted string to an HTML file instead of printing it to the terminal?
I can give you the exact command/script for your specific setup.



