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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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