Jump to content

variable variables


phoenixx

Recommended Posts

I've "scraped" some data from one of my other sites and need to assign dynamically increasing variables:

 

Heres some sample code.  In the end, each output row will have

 

$variable1 = $k . " " . $v;

$variable2 = $k . " " . $v;

etc...

 

$data = @file_get_contents("https://XXX/index.php?inputEmailHandle=XXX", "r");  ;

preg_match_all('/<input.*?name="([^"]*)".*?value="([^"]*)"/is',$data,$out);

$d = array_combine($out[1], $out[2]);

//$insert_into = array();

foreach($d as $k=>$v){

echo $variablevariable . " = " . $k . " = " . $v . "<br>";

}

 

Link to comment
https://forums.phpfreaks.com/topic/118150-variable-variables/
Share on other sites

Example of variable variable

$str = 'hello';

${$str . 'world'} = 'hi';

echo $helloworld; // outputs hi

 

In your case you'll need to implement a counter. However it'll be better to use an array instead (after all this is what their there for)

Link to comment
https://forums.phpfreaks.com/topic/118150-variable-variables/#findComment-607864
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.