Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在将变量从一个php文件传递到另一个php文件时遇到问题_Php_Xml_Json_Php Parser - Fatal编程技术网

我在将变量从一个php文件传递到另一个php文件时遇到问题

我在将变量从一个php文件传递到另一个php文件时遇到问题,php,xml,json,php-parser,Php,Xml,Json,Php Parser,我试图将变量数据从php1.php传递到php2.php。 $html = ""; $url = "http://www.conciencia.net/rss.aspx"; $xml = simplexml_load_file($url); $channel_title = $xml->channel->title; $channel_link = $xml->channel->link; $managingEditor = $xml->channel->m

我试图将变量数据从php1.php传递到php2.php。
$html = "";
$url = "http://www.conciencia.net/rss.aspx";
$xml = simplexml_load_file($url);

$channel_title = $xml->channel->title;
$channel_link = $xml->channel->link;
$managingEditor = $xml->channel->managingEditor;
$channel_description = $xml->channel->description;
$lbd = $xml->channel->lastBuildDate;

$html .= "<br/>$channel_title";
$html .= "<br/>$channel_link";
$html .= "<br/>$managingEditor";
$html .= "<br/>$lbd";
$html .= "<br/>$channel_description";

for($i = 0; $i < 7; $i++){

    $pubDate = $xml->channel->item[$i]->pubDate;
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
    $guid = $xml->channel->item[$i]->guid;
    $author = $xml->channel->item[$i]->author;
$description = $xml->channel->item[$i]->description;


    $html .= "<br/>$pubDate";     
$html .= "<a href='$link'><h3>$title</h3></a>";
    $html .= "$link";
    $html .= "<br/>$guid";
    $html .= "<br/>$author";
$html .= "<br/>$description";


}

echo $html;
?>
这就是我想做的:

我使用php从一个url加载一个未经feedvalidator.org验证的xmlnot,然后将变量数据传递给另一个php2.php。这一个将创建一个json文件。我没有使用php函数将xml转换为json,因为我正在更改结构。 这两个文件分别工作得很好:php1.php正确加载xml,php2.php创建我想要的json结构,我的问题是:我无法将变量数据从php1.php传递到php2.php。
$html = "";
$url = "http://www.conciencia.net/rss.aspx";
$xml = simplexml_load_file($url);

$channel_title = $xml->channel->title;
$channel_link = $xml->channel->link;
$managingEditor = $xml->channel->managingEditor;
$channel_description = $xml->channel->description;
$lbd = $xml->channel->lastBuildDate;

$html .= "<br/>$channel_title";
$html .= "<br/>$channel_link";
$html .= "<br/>$managingEditor";
$html .= "<br/>$lbd";
$html .= "<br/>$channel_description";

for($i = 0; $i < 7; $i++){

    $pubDate = $xml->channel->item[$i]->pubDate;
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
    $guid = $xml->channel->item[$i]->guid;
    $author = $xml->channel->item[$i]->author;
$description = $xml->channel->item[$i]->description;


    $html .= "<br/>$pubDate";     
$html .= "<a href='$link'><h3>$title</h3></a>";
    $html .= "$link";
    $html .= "<br/>$guid";
    $html .= "<br/>$author";
$html .= "<br/>$description";


}

echo $html;
?>
我已经试过了: 和 我还没能让代码正常工作

我正在尝试传递:$lbd、$title、$guid、$author、$description

-谢谢

这是我的代码:

php1.php
$html = "";
$url = "http://www.conciencia.net/rss.aspx";
$xml = simplexml_load_file($url);

$channel_title = $xml->channel->title;
$channel_link = $xml->channel->link;
$managingEditor = $xml->channel->managingEditor;
$channel_description = $xml->channel->description;
$lbd = $xml->channel->lastBuildDate;

$html .= "<br/>$channel_title";
$html .= "<br/>$channel_link";
$html .= "<br/>$managingEditor";
$html .= "<br/>$lbd";
$html .= "<br/>$channel_description";

for($i = 0; $i < 7; $i++){

    $pubDate = $xml->channel->item[$i]->pubDate;
$title = $xml->channel->item[$i]->title;
$link = $xml->channel->item[$i]->link;
    $guid = $xml->channel->item[$i]->guid;
    $author = $xml->channel->item[$i]->author;
$description = $xml->channel->item[$i]->description;


    $html .= "<br/>$pubDate";     
$html .= "<a href='$link'><h3>$title</h3></a>";
    $html .= "$link";
    $html .= "<br/>$guid";
    $html .= "<br/>$author";
$html .= "<br/>$description";


}

echo $html;
?>

添加会话(u start);;在每个文件的开头,在回显任何内容之前。然后在文件1的末尾添加以下内容:

$_SESSION['lbd'] = $lbd;
$_SESSION['title'] = $title;
$_SESSION['guid'] = $guid;
$_SESSION['author'] = $author;
$_SESSION['description'] = $description;
然后,在第二个选项中,添加:

$lbd = $_SESSION['lbd'];
$title = $_SESSION['title'];
$guid = $_SESSION['guid'];
$author = $_SESSION['author'];
$description = $_SESSION['description'];

变量现在应该可用了

要传递的变量是什么?第一个文件中没有$feed!我已经更新了我的问题。我尝试传递的变量现在已发布。您不能在脚本之间传递变量。每个脚本在每个http请求进入时分别执行,并且在任何两个+php进程之间都没有共享代码。如果希望一个脚本中的数据显示在另一个脚本中,则必须以某种方式传递它。e、 g会话、查询参数、表单字段等。@Marc B如何处理会话?谢谢@motanelu,我已经尝试过了,但还没有得到变量。