dongmu5920 2014-03-21 10:11
浏览 22

php包含变量而不包括

Can some one tell me how to "include" a variable from another .php file without all its other content.

index.php

<?php
$info=file('somedir/somefile.php');
$v1=trim($info[2]);
$v2=trim($info[3]);
$v3=trim($info[4]);
?>

the somedir/somefile.php

<?php
$variable=something;
$variable2=someotherting;
$variable3=thirdone!;
All the other content there may not be runned or showed.
?>

Can anybody please help me??

Edit:

Its for my dynamic page.

<html>
    <?php
    include_once 'config.php';
    include_once 'includes/mysqlconnect.php';
    $url_slash=$_SERVER['REQUEST_URI'];
    $url= rtrim($url_slash, '/');
    //$url = basename($url);
    $info=file('sites/'.$url.'.php');
    $title=trim($info[2]);
    ?>
    <head>
        <meta charset="UTF-8">
        <title>$title</title>
        <link rel="stylesheet" type="text/css" href="<?php echo $domain;?>themes/reset.css">
        <link rel="stylesheet" type="text/css" href="<?php echo $domain;?>themes/<?php echo $theme;?>.css">
    </head>
    <body class="body">
        <div class="container-all">
            <?php include_once 'includes/header.php';?>
            <div class="container">
                <?php include_once 'includes/navigationbar.php';?>
                <?php include_once 'includes/rightsidebar.php';?>
                <div class="content"><?php

                if ($url==''){

                    include_once "sites/home.php";
                }
                elseif (file_exists("sites/$url.php") && is_readable('/var/www/html/sites/'.$url.'.php')){
                    include_once '/var/www/html/sites/'.$url.'.php';

                }

                else {
                    include_once 'sites/404.php';

                }


                ?></div>
                <?php include_once 'includes/footer.php';?>
            </div>
        </div>
    </body>
</html>

Hope you understand my question now.

  • 写回答

3条回答 默认 最新

  • douhua1890 2014-03-21 10:15
    关注

    Save the variables in a separate file that can be included separately. Do it the sane way. Structure your code properly, don't try to invent solutions for problems you have because your structure is messy.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。