How I answer PHP questions on Stack Overflow
Am I overdoing it? Probably. Do I care? No.✍️ Jacob Mulquin
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:
- Open 3v4l or similar online playground
- Copy and paste code from the question
json_decodeor some other data transformation so it could actually be used
- Iterate and play around
Since I was getting bored of manually transcoding a
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:
- Take a Stack Overflow question page, extract the ID
- Create a folder for the answer
- Scrape the question page, dump into a file
- Extract any codeblocks that are in the question and dump into separate files
- Create a PHP file ready for me to edit with reference to the useful helper functions listed above
- 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