从第行的另一个php文件中获取变量

从第行的另一个php文件中获取变量,php,Php,从第行的另一个php文件中获取变量 你好 是否可以从另一个PHP文件中获取值 从特定行读取变量 范例 file1.php <?php echo 'my variable is'; //reading the variable from line 3 ?> file2.php <?php /*this is line 1*/ /*this is line 2*/ $var = 'hello world'; /*this is line 3*/ ?> 您可以在页

从第行的另一个php文件中获取变量

你好 是否可以从另一个PHP文件中获取值 从特定行读取变量 范例

file1.php

<?php
echo 'my variable is';
//reading the variable from line 3
?>

file2.php

<?php
/*this  is line 1*/
/*this  is line 2*/
$var = 'hello world'; /*this  is line 3*/
?>

您可以在页面中创建文件。

在file1.php中使用include或require:

<?php
include 'file2.php';
//require 'file2.php';
echo 'my variable is '.$var;
//reading the variable from line 3
?>

这可能会帮助您>>是否可以从特定行读取变量