How to Include an echo function in Include function in PHP?

Ask A Question

Login To post a question

I want to include a file using a PHP include function. But the file name has to be generated dynamically.

For example:

We have URL as
I want to include test-sidebar.php file.

If we have URL as
I want to include test2-sidebar.php file.

I tried using the following code but unsuccessful.

Please help me, Thanks in Advance.

$editedpageurl = str_replace("/", " ", $pageurl);
$pieces = explode(' ', $editedpageurl);
$last_word = array_pop($pieces);

$sidebar = $last_word."sidebar.php";
include_once('echo $sidebar;');

For more info please click here

Have a question or need a custom quote?