0
$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

in00b
  • 99
  • 1
  • 3
  • 9
  • Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – mickmackusa Jun 14 '17 at 04:14

1 Answers1

2
$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 .

Tony
  • 2,890
  • 1
  • 24
  • 35
  • will try it now. Though I thought of that and thought it wouldn't work in preg_match how stupid am I gonna feel if it works lol. Will let you know thanks – in00b Jun 13 '17 at 22:30