Jacob Mulquin

How I answer PHP questions on Stack Overflow

Am I overdoing it? Probably. Do I care? No.

✍️ Jacob Mulquin
📅 09/10/2022

I like to answer PHP questions on Stack Overflow. I've been doing it for a while and begun to notice some patterns of behaviour in the process of answering:

Since I was getting bored of manually transcoding a var_dump or print_r statement, I searched online for some functions to automatically convert the output back to usable PHP arrays.

These two functions are bloody useful for answering PHP questions on Stack Overflow!

But I didn't stop there. Oh no, I had to go further.

I wanted a script that would do the following:

  1. Take a Stack Overflow question page, extract the ID
  2. Create a folder for the answer
  3. Scrape the question page, dump into a file
  4. Extract any codeblocks that are in the question and dump into separate files
  5. Create a PHP file ready for me to edit with reference to the useful helper functions listed above
  6. Navigate to the created folder and launch the PHP file

Here's a look at the basic workflow in action:

I've put it up at Github if you wanted to have a look at the code: mulquin/stackoverflow_helper