Recently, an old friend of mine rang me up to ask for help. He’d been working as a journalist for many years, and had recently received reprint rights to a number of his earlier columns.
He was eager to publish his past work on the Web; however, his columns were all saved as plain-text files and he had neither the time nor the inclination to learn HTML and convert them to Web pages. Since I was the only geek in his phone book, he’d called me to see if I could help him.
“Let me take care of it”, I said. “Call me back in an hour”, I said. And sure enough, when he called back a couple of hours later, I had a solution waiting for him. It involved a little bit of PHP, and it earned me his eternal thanks and a crate of wine.
So what did I do in that hour? That’s where this article comes in. I’m going to show you how you can use PHP to quickly transform plain ASCII text into perfectly readable HTML markup.
To begin, let’s look at an example of one of the raw text files my friend wanted to convert: