I'm calling a webservice that returns an XML document. When I call it it returns the following:
resultsetrecordtxnref1013101155943920/txnrefchannelvisa/channelamount1000.00/amountpayment_date4/11/2013 3:59:43 PM/payment_datepayment_statussuccessful/payment_statusfield_valuesfield_valuesfieldnamesTest Test/namesacct_descFalse/acct_descacct_desc_order0/acct_desc_orderhiddenFalse/hiddendefaultvalue /xpath_field0/xpath_field/fieldfieldamount1000.00/amountacct_descFalse/acct_descacct_desc_order0/acct_desc_orderhiddenFalse/hiddendefaultvalue /xpath_field0/xpath_field/fieldfieldcurrencyNGN/currencyacct_descFalse/acct_descacct_desc_order0/acct_desc_orderhiddenFalse/hiddendefaultvalue /xpath_field0/xpath_field/fieldfieldemail_addresstest/email_addressacct_descFalse/acct_descacct_desc_order0/acct_desc_orderhiddenFalse/hiddendefaultvalue /xpath_field0/xpath_field/fieldfieldphone_number+2348031155249/phone_numberacct_descFalse/acct_descacct_desc_order0/acct_desc_orderhiddenFalse/hiddendefaultvalue /xpath_field0/xpath_field/fieldfieldmerch_txnref0/merch_txnrefacct_descFalse/acct_descacct_desc_order0/acct_desc_orderhiddenFalse/hiddendefaultvalue /xpath_field0/xpath_field/field/field_values/field_valuespayment_status_descriptionTransaction Successful - Approved/payment_status_description/record/resultset
Is this valid XML because when I use simplexml_load_string it works on my local server which runs PHP 5.4 but not on my testing server which uses PHP 5.3
This is a result of your browser parsing the XML and ignoring all the tags. Try viewing the page source or using a browser that can handle XML.
For some reason setting turning on the php_openssl.dll fixed the problem. Not sure why ... but google says so
Related
I'm trying to find a way to load my latest tweet with PHP.
At this URL, I change "Twitter.xml" to my username-".xml."
https://twitter.com/users/show/Twitter.xml
The latest tweet is shown on line 49, but I don't think PHP can read a remote file... I want it to show line 49, but how do I combine it with finding a file on a remote server?
Thanks
In PHP you can use file_get_contents() to get the contents of that url. For example
$xml = file_get_contents('https://twitter.com/users/show/Twitter.xml');
This will only work if the config setting for allow_url_fopen is set to On
Use curl to fetch a remote resource.
http://www.php.net/manual/en/curl.examples-basic.php
http://www.php.net/manual/en/function.curl-init.php
Then, since it's xml, I would convert it to a native PHP object, using SimpleXML
http://www.php.net/manual/en/simplexml.examples-basic.php
I'm trying to retrieve an webpage that has XML data using file_get_contents().
$get_url_report = 'https://...'; // GET URL
$str = file_get_contents($get_url_report);
The problem is that file_get_contents gets only the secure content of the page and returns only some strings without the XML. In Windows IE, if I type in $get_url_report, it would warn it if I want to display everything. If I click yes, then it shows me the XML, which is what I want to store in $str. Any ideas on how to retrieve the XML data into a string from the webpage $get_url_report?
You should already be getting the pure XML if the URL is correct. If you're having trouble, perhaps the URL is expecting you to be logged in or something similar. Use a var_dump($str) and then view source on that page to see what you get back.
Either way, there is no magic way to get any linked content from the XML. All you would get is the XML itself and would need further PHP code to process and get any links/images/data from it.
Verify if openssl is enable on your php, a good exemple of how to do it:
How to get file_get_contents() to work with HTTPS?
I'am building simple Ajax application (via jquery). I have strange issue. I found where the problem is, but I don't know how to solve it.
This is simple server-side php code:
<?php
require('some.php');
$return['pageContent'] = 'test';
echo(json_encode($return));
?>
On the client side, the error "Invalid JSON" is thrown.
I have discovered that if I delete require function, everything work fine.
Just for information, the "some.php" is an empty php file. There is no error when I open direct php files.
So, conclusion: I cant use require or include function if I want to use ajax?
Use Firebug to see what you're actually getting back during the AJAX call. My guess is that there's a PHP error somewhere, so you're getting more than just JSON back from the call (Firebug will show you that). As for your conclusion: using include/require by itself has absolutely no effect on the AJAX call (assuming there are no errors).
Try changing:
<?php
require('some.php');
$return['pageContent'] = 'test';
echo(json_encode($return));
?>
To:
<?php
$return = array(
'pageContent' => 'test'
);
echo json_encode($return);
?>
The problem might have to do with $return not being declared as an array prior to use.
Edit: Alright, so that might not be the problem at all. But! What might be happening is you might be echoing out something in the response. For example, if you have an error echoing out prior to the JSON, you'd be unable to parse it on the client.
if the "some.php" is an empty php file, why do you require it at all?!
require function throws a fatal error if it could't require the file. try using include function instead and see what happens, if it works then you probably have a problem with require 'some.php';
A require call won't have any effect. You need to check your returned output in Firebug. If using Chrome there is a plugin called Simple REST Client. https://chrome.google.com/extensions/detail/fhjcajmcbmldlhcimfajhfbgofnpcjmb through which you can quickly query for stuff.
Also, it's always good to send back proper HTTP headers with your response showing the response type.
It's most likely the BOM as has been discussed above. I had the same problem multiple times and used Fiddler to check the file in hex and noticed an extra 3 bytes that didn't exist in a prior backup and in new files I created. Somehow my original files were getting modified by Textpad (both in Windows). Although when I created them in Notepad++ I was fine.
So make sure that you have your encoding and codepages set up properly when you create, edit, and save your files in addition to keeping that consistent across OSes if you're developing on windows let's say and publishing to a linux environment at your hosting provider.
I need to find a way to get all Apache running request at a given moment. I need to list the vhost, cpu, request ip address and some other information.
This information will be consumed by a PHP script.
I have mod_status installed and it has all the information I need. So I tried to use file_get_contents to get the report, generating a request from the server (http://localhost/server-status). It worked perfectly. Then I tried to parse the report, converting it to XML using simplexml_load_string. The problem is that the HTML outputted by mod_status is not well formed.
Here is the HTL from the table I need to parse:
<table border="0"><tr><th>Srv</th><th>PID</th><th>Acc</th><th>M</th><th>CPU
</th><th>SS</th><th>Req</th><th>Conn</th><th>Child</th><th>Slot</th><th>Client</th><th>VHost</th><th>Request</th></tr>
<tr><td><b>0-1</b></td><td>-</td><td>0/0/70</td><td>.
</td><td>0.00</td><td>107</td><td>0</td><td>0.0</td><td>0.00</td><td>0.34
</td><td>127.0.0.1</td><td nowrap>zsce</td><td nowrap>OPTIONS * HTTP/1.0</td></tr>
<tr><td><b>1-1</b></td><td>-</td><td>0/0/55</td><td>.
</td><td>0.04</td><td>108</td><td>0</td><td>0.0</td><td>0.00</td><td>0.70
</td><td>127.0.0.1</td><td nowrap>zsce</td><td nowrap>OPTIONS * HTTP/1.0</td></tr>
</table>
I'm sure someone has tried to do something like this before.
1) Is there another way to access the information I need?
2) Has anybody tried other tools / modules?
Thanks in advance.
I can't see the problem with the HTML. What's wrong with it?
Does PHP not have a liberal HTML parser; something like Python's BeautifulSoup or Ruby's Nokogiri?
Also, remember that mod_status has 'auto' mode for producing machine-readable output.
http://www.apache.org/server-status?auto
http://httpd.apache.org/docs/2.2/mod/mod_status.html#machinereadable
I just found that if I remove "nowrap" from the HTML before parsing it, it works.
I'm having trouble figuring out what my Flex Project is expecting from my PHP file in-relation to HTTP Service. Can anyone give a link or an example as to what the PHP file should return? I already configured the return type of the Operation to String. Then on my PHP file, I put in a simple line of code
<?php
echo "hello world";
?>
but the problem is, whenever I try to test the Operation, Flash Builder keeps telling me InvocationTargetException:The response is not a valid XML or a JSON string
I want to see a working example of interactions between a Flex Project and an HTTP Service...
Flash Builder expects an XML or JSON as a result.
So in your php file you'll have to wrap the result as a XML (or JSON):
<?xml version="1.0"?>
<theresult>
<thestring>hello world</thestring>
</theresult>