D
D
DestroyerZzz2015-10-10 20:17:16
PHP
DestroyerZzz, 2015-10-10 20:17:16

Code inside. How to put include into a variable?

<? $siteMenu="<? 
include $_SERVER['DOCUMENT_ROOT'].'/core/modules/menu.php';
?>" ?>
Does not work. Why? how to shove ikludu into a variable?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
Pavel Volintsev, 2015-10-10
@DestroyerZzz

Option 1.
the contents of the menu.php file should be like this

<?php
return array(
    "пункт меню 1",
    "пункт меню 2",
    "пункт меню 3",
);

Option 2.
<?php
function getMenu()
{
  ob_start();
  include $_SERVER['DOCUMENT_ROOT'].'/core/modules/menu.php';
  return ob_get_clean();
}

$siteMenu = getMenu();

the contents of the menu.php file should be like this
<ul><li>пункт меню 1</li><li>пункт меню 2</li><li>пункт меню 3</li></ul>

D
DrunkMaster, 2015-10-10
@DrunkMaster

//Файл отдельный one.php в нём:
$siteCore = "<link rel="stylesheet" type="text/css" href="/core/css/style.css">
<link rel="stylesheet" type="text/css" href="/core/css/adaptive.css">
<link rel="stylesheet" type="text/css" href="/core/font/styles.css">
<link rel="icon" type="image/gif" href="/core/img/favicon.gif">"

//Теперь код основного сайта
include 'one.php';
echo "$siteCore";

M
Mokhirjon Naimov, 2015-10-10
@zvermafia

Try it:

$site_menu = function() {
    include $_SERVER['DOCUMENT_ROOT'] . '/core/modules/menu.php';
}

I
Ivanq, 2015-10-10
@Ivanq

Throwing code into eval is bad practice. It is better to write the address to the variable, and then include $menu;
And even better, create the show_menu () function in the file and call it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question