简体   繁体   English

在单个php页面中读取两个rss / xml文件

[英]reading two rss/xml files in a single php page

I have a script where i need to pull two seperate and different RSS feeds, break them up, assign variables, and execute code thats different for each file. 我有一个脚本,需要提取两个单独的不同的RSS提要,分解它们,分配变量,并为每个文件执行不同的代码。

What im wondering, and i dont know if this can even be done, but once i use a function and give it settings, can i then re-use that function with different settings even though some of its internal variables will have different values? 我想知道的是什么,我什至不知道这是否可以完成,但是一旦我使用了一个函数并为其设置了设置,即使某些内部变量具有不同的值,也可以以不同的设置重新使用该函数吗?

say the first time i run it, it looks like this 说我第一次运行它,它看起来像这样

$xml = simplexml_load_string($raw_xml);

foreach($xml->channel as $channel)

then i run 然后我跑

$xml = simplexml_load_string($raw_xml2);

foreach($xml->item as $item)

Will I get errors or redundant data because i re-used the XML variable? 重复使用XML变量会导致错误或冗余数据吗?

Not at all. 一点也不。 Assigning a new value to a variable completely overwrites the first value. 为变量分配新值将完全覆盖第一个值。 The code you posted should work fine. 您发布的代码应该可以正常工作。

Just assign it to a different variable. 只需将其分配给其他变量即可。 Very easy. 很容易。

It totally depends on what simplexml_load_string does. 这完全取决于simplexml_load_string功能。 Suppose the implementation uses globals: 假设实现使用全局变量:

function simplexml_load_string() {
    global $a;
    $a++; /* we're increasing the global value of $a each time the function is called */ 
}

It will definitely output unidentified behavior. 它肯定会输出未知的行为。

Other than that, local variables storage will be deleted and pushed on the stack everytime. 除此之外,局部变量存储每次都会被删除并压入堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM