Jump to content

function help


devWhiz

Recommended Posts

So I want to be able to make a function that will will parse the XML from my string every time it is called, so say I have this

 

$Result = file_get_contents('http://www.example.com');

 

Which loads this

 

<outer>
    <xml>
        <viewer>
            <user>
                <name>bradley</name>
                <age>18</age>
                <location>ohio</location>
            </user>
        </viewer>
    </xml>
</outer>

 

I parse it with

 

$xml = simplexml_load_string($Result);
foreach($xml->xml->viewer->user as $xml2)
    {
    $name = $xml2->name;
    $age = $xml2->age;
    $location = $xml2->location;
    }

 

Is there a way possible maybe a function that will be able to allow me to do something like this

 

<?php

$Result = file_get_contents('http://www.example.com');
xml_parse($Result);
echo $name;

$AnotherResult = file_get_contents('http://www.example.com');
xml_parse($AnotherResult);
echo $name;



?>

 

Is it possible for me to make a function that stores the xml parse information and it uses it every time it is called on the string that is in the "( )"

 

I am completely illiterate to making functions so every bit of help I can receive is appreciated

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/236373-function-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.