简体   繁体   中英

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.

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?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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