I am a little new to the PHP world and despite my googling and manual reading, I can't
I am currently (ethically!) scraping a website that has a number of different categories (let us call them 'alpha', 'beta', 'gamma').
Currently, I go through these steps:
- Load the file
- Locate the correct table (php_siomple_dom)
-
Then go through the elements to grab the information.
$alpha_one = $element -> find etc; $alpha_two = $element -> find etc; $alpha_n = $element -> find etc; $beta_one = $element -> find etc; $beta _two = $element -> find etc; $beta_n = $element -> find etc;
-
All of the tables are the same for alpha, beta, gamma; thus I would like to write a function, but I am struggling with how to include the argument name in the variables I create. This was my idea, but it does not work.
function grab($argument) { $argument . "_one" = $element -> find etc; $argument . "_two" = $element -> find etc; $argument . "_n" = $element -> find etc; }
Thus, I could use:
grab('alpha');
grab('beta');
grab('gamma');
without having to write out the code for each table
I've looked into 'magic methods', but cannot swing it into working. I would really appreciate if some PHP wizard could shed some light upon this. Thank youu!