faalbane
faalbane

Reputation: 81

PHP include dynamically generated filename?

while($x<=$num_of_cpkgs){
  $cpkg_navtray = '\'' . $cpkg_array[$x] . '.html\'';
  include $cpkg_navtray;
  $x++;
}

I'm getting an error when I try this ... it works when I manually include the same value however ... for example, if $cpkg_navtray = 'test.html', I'm getting an error; however, when I directly include 'test.html' like include 'test.html';, it works. Why?

Upvotes: 0

Views: 45

Answers (2)

Murad Hasan
Murad Hasan

Reputation: 9583

Looking same Question but tag and desire different: Jut do these, just a simple concatenate.

while($x<=$num_of_cpkgs){
  $cpkg_navtray = $cpkg_array[$x].'.html';
  include $cpkg_navtray;
  $x++;
}

Upvotes: 1

splash58
splash58

Reputation: 26153

You dont need quotes in filename variable -

$cpkg_navtray = $cpkg_array[$x] . '.html';

Upvotes: 2

Related Questions