php - Include file inside foreach loop -



php - Include file inside foreach loop -

is not possible utilize php include within foreach loop?

i have array of filenames called $posts:

array ( [3] => post-an-example-post.html [4] => post-my-first-test-post.html [5] => post-my-second-test-post.html )

and want output contents of each of these (which simple html) each item in array:

foreach ($posts $post){ $post = "/posts/" . $post; echo $post; include $post; }

this gives me error each one, won't utilize origin / have added , instead stays within same file?:

warning: include(/posts/post-an-example-post.html): failed open stream: no such file or directory in /applications/mamp/htdocs/quick-blog/showposts.php on line 7

the files stored in /posts/ directory.

edit: here how array $posts created. scans directory , removes doesn't start posts-

function postarray(){ $dir = 'posts'; $files = scandir($dir); $posts = array_filter( $files, function($value) { homecoming (strpos($value, 'post-') === 0); } ); homecoming $posts; }

you giving absolute location include. looking directory called posts @ top of filesystem, not document root.

php foreach include

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -