I want to include a file using a PHP include function. But the file name has to be generated dynamically.
We have URL as domain.com/test
I want to include test-sidebar.php file.
If we have URL as domain.com/test2
I want to include test2-sidebar.php file.
I tried using the following code but unsuccessful.
Please help me, Thanks in Advance.
$pageurl = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $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 herehttps://stackoverflow.com/q/56626604