Webpages and Gists (and PHP)
A while back I wrote about webpages from gists. I must have a “thing” about this, because I’ve been pondering other ways of using gists to display things on the web.
And now another possibility presents itself. I want to be able to update two different webpages—with qutie different formats—with the same content. Of course, I don’t want to do that twice, so the thought of pulling the content from a gist came to mind. There are a number of ways of embedding gists on webpages, but none worked so well for me.
So, it was PHP to the rescue. The file_get_contents()
function does just what I want. If the gist is written in plain HTML, then one can use this to pull that content into another webpage (assuming that it terminates in .php
):
$url = "https://gist.githubusercontent.com/userid/c6179aed9baf93fa5124198c17eac5e6/raw/preface.html";
$text = file_get_contents($url);
echo $text;
This styles beautifully on its “new” pages, each in their own very different way.
And it doesn’t get much simpler than that! This is hardly rocket science (let alone brain surgery), but it took me a little head scratching.