parsing \\xc3\\xb6 from a url - php

I'm trying to support an API, it's a remote server pushing data to me. When passing data, reading directly from $_GET['value'] I get strings with this in them:
\xc3\xb6
They also needed a very specific url structure, which I've had to use curl to work around. When using curl on the api I get this instead:
\xc3\xb6
Is the problem on my side or on his? How can I decode this reliably? Is there a better way than using curl available? (If neccesary I'll recode that part of it to skip curl, I just wanna get it working at this point).
//edit : Note that I'm writing the $_GET['value'] directly to a file to test. And it looks the same.

Related

PHP - Fetch multiple URLs by chunks

My web application needs to parse remote resources from multiple remote servers. The problem is that the output of those remote servers is long / staged. I hence need a piece of code implementing the following logic:
Populate array $links_array with a set of links.
Some code here....
For $i in count($links_array)
`$results_array[$i] = {what has been output until now without waiting for full response}
Some code here....
The answer must not use extensions (except cURL) and work on PHP 5.3.
Thanks a lot for your help.
It seems like you need an asynchronous method of download links. You can look into the Guzzle Library (https://blog.madewithlove.be/post/concurrent-http-requests/). Another option is to use multi curl: http://php.net/manual/en/function.curl-multi-init.php

Parsing - can't get data from PHP file

I'm trying to parse data from http://skytech.si/
I looked around a bit and I find out that the site uses http://skytech.si/skytechsys/data.php?c=tabela to show data. When I open this file in my browser I get nothing. Is the file protected and can run only from server side or something?
Is there any way to get data from it? If I cold get HTML data (perhaps in a table?) I would probably know how to parse it.
If not, would it be still possible to parse website and how?
I had a look at the requests made;
http://skytech.si/skytechsys/?c=graf&l=bf0b3c12e9b2c2d65bd5ae8925886b57
http://skytech.si/skytechsys/?c=tabela
Forbidden
You don't have permission to access /skytechsys/ on this server.
This website doesn't allow 'outside' GET requests. You could try parsing the data via file-put-contents but I don't think you will be able to get specific data tables (aside from those on that home) due to AJAX requests that need to be made. I believe the /data? is the controller to handle data which is not exposed via the API.
When you open this URL in your browser you send GET request. Data returned under this address is accessible after sending POST request with params as follows c:tabela, l:undefined, x:undefined. Analyze headers next time and look on Network log if you are using Chrome/Chromium.
If that website does not expose an API, it is not recommended to parse the data, as their HTML structure is prone to change.
See:
http://php.net/manual/en/function.file-put-contents.php
And then you can interpret it with an HTML-parsing engine or with an regular expression (not recommended).

file_get_contents doesn't work as well as direct string?

Its seems like file_get_contents is not working exactly returning a true string value, otherwise it's different.
For example i'm working on a rest API to which I have to send contents via json. One of theses contents is a xml file content.
When I put the xml straight as a var's value, striping slashes, it works. But if I do a file_get_contents() on a file containing the exact same xml (with or without slashes), It doesn't.
Has someone already seen this happening ? If yes, does some one know how I handle this ?
Thanks
To answer my own question :
Actually the probleme was that when I did file_get_contents() on a xml file, it returned html encoded characters when I echoed it.
But if, instead of doing so, I just putted a $var = "<my xml definition>"; and echoed it as well, the encoding was not the same. Which made me think that using file_get_contents or not made a really big difference when trying to make REST requests.
I precise that I was trying to pass via ajax to php, xml definition using json.
Actually it was the api which was not working, because of maintainance. And as they didn't communicate on that I was thinking that I was wrong and that my code had mistakes.
So to conclude : file_get_contents() seems to work just fine and as expected.
I hope this clear and long answer wont knockdown my reputation this time :)

How to use function call in external PHP url

I understand that within same folder, I can use include() function for external PHP file, but now I would like to call the function in another PHP file which located in another URL.
For example, my live website (liveexample.com/table.php) has drop-down list and table, but without data.
My another PHP file (dataexample.com/data.php) is connected to database and process to extracting data out. But, it is in another server.
I need to make my data on [dataexample.com/data.php] delivers to [liveexample.com/table.php] and let the looping to draw table with data out on [liveexample.com/table.php] page.
Anyone has idea to design this method of delivering data from another server to another by using function call in PHP?
Or any other better solution to deliver my data between two different servers such as make the data record set into array and send to [liveexample.com/table.php]?
Please give me advise or consultation. Appreciate much!
I think SOAP webservice would be perfect for you to attain what you want but if possible just copy the same codes you have from the separate server.
If you make [dataexample.com/data.php] output your data as XML, then you can use it as a web service. What that means is, you can take that XML output (by sending a request the the data URL), and then parse it to load the data. This way, you can use that service any way you want. One way would be like you wanted, other examples would be via AJAX, or Flash etc.
So here are a few topics worth looking into:
using PHP for web services: http://wso2.org/library/3032
parsing XML data: http://www.w3schools.com/php/php_xml_simplexml.asp
I hope this will give a pretty good idea of how to achieve what you want to accomplish, because there a few options you can go by. Like Cristopher said, SOAP is one of them.
Have a great day.

Send JSON from php processing to public coldfusion page

I am modifying someones existing coldfusion web app. I am adding php processing pages to do various tasks. Up to this point I have just been calling the php pages, and interacting with the web app by passing variables via the url.
Current usage:
public.cfm calls processing.php?id=69
Then processing will do what it has too, then ultimately:
header("Location: $publichome?id=$id&importantstuff=$stuff");
exit();
And the webapp will pick up where it has too. But now one of my scripts has to send a JSON object back instead of simple variables. I don't know how to get this done. I tried doing a post with cURL but that wasn't working because I need the public facing coldfusion page to take over and curl returns to the php script (I know I can echo the body of the curl result but this keeps me on the php script domain which I dont want). Is there a way to do the above header location and send an object because thats what I need - the php script to stop and the coldfusion page to be served up with the object to work with.
Do I have to create some sort of JSON service in php, that the coldfusion page will call an retrieve the result? I can also modify the coldfusion page any way I want.
You should be able to pass the json string as a URL variable, just like you are passing simpler strings, through the location header. You will need some means of json-serializing the object in php, if you haven't done that yet. There is likely a json library available to do that.
edit
Based on more information, I now have a better suggestion:
From CF, make a <cfhttp> request to your PHP code, passing whatever parameters are necessary to PHP as arguments in cfhttp. From PHP, simply "output" the JSON as the response body. After the CFHTTP call returns to CF, you'll have access to the JSON via the cfhttp.fileContent variable, which you can then run through DeserializeJSON to get back a real object. Here some sample CF code:
<cfhttp url="processing.php?id=69" method="get"></cfhttp>
<cfset importantStuff=DeserializeJSON(cfhttp.fileContent)>

Categories