Jump to content

Read fsockopen result?


ruraldev

Recommended Posts

Can anyone help me print the output from fsockopen, I create a variable called $var

 

It returns an xml format

 

<tag>

    <element1>one</element1>

    <element2>two</element2>

    <element3>three</element3>

</tag>

 

I can output the values onetwothree using fputs and fgets but I need to be able to display just a single element, I am sure this is simple but I still can't work it out.

 

Hope someone can help.

 

Thanks

 

Gordon

Link to comment
Share on other sites

'Neither worked' is a horrible error report. I can't help you without more details.

 

I assure you, SimpleXML is probably the ideal solution to this, unless you don't mind manually parsing with RegEx

Link to comment
Share on other sites

I couldn't find a way to select the different elements using fgets, is it possible?

 

 

Use the results from fgets to generate your SimpleXML instance.

 

This might be beyond your current PHP abilities.

Link to comment
Share on other sites

Code is below, however it wouldn't work live as the remote machine is behind a firewall and only certain IP's are allowed through. It does get a response as I can see it but it is just a single long string.

 

You may well be correct that this is beyond my abilities!

 

 

$var = fsockopen($svr_add,$svr_port,$errno,$errstr,$svr_timeout);

 

if(!$var)

    {

    echo "Connextion Failed\n";

    exit();

    }

else

    {

fputs ($var, $xml_data);

 

echo fgets ($var, 128);

 

fclose($var);

    }

 

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.