Reputation: 109
$websitecontent = file_get_contents('http://website.com');
$variable1 = 'Nissan_GTR';
$variable2 = '2017';
preg_match('~<a href="(.*?)" ><img src="https://website.com/perma/$variable1_$variable2.jpg"~',$websitecontent,$results);
print_r($results);
exit();
as you see above is what I am trying to do I am trying to use variables inside pregmatch. No idea on how to do it. I did try searching before asking the question some were similar but none of them really helped me with the problem. Thanks
Upvotes: 0
Views: 33
Reputation: 3068
$websitecontent = file_get_contents('http://website.com');
$variable1 = 'Nissan_GTR';
$variable2 = '2017';
preg_match('~<a href="(.*?)" ><img src="https://website.com/perma/' . $variable1 . '_' . $variable2 . '.jpg"~',$websitecontent,$results);
print_r($results);
exit();
You need to separate the variables with .
Upvotes: 2