I'm trying to get (with PHP) data from a remote text file. The URL of the file is website.com/page.php?info=someinfo. So it's not a .txt file, I don't know if that matters. The whole contents of the page are text, however. When looking at the source, there is no HTML, only plain text.
I've been trying to get the data using fopen() and fread(), and file_get_contents. However, both methods give me a screen filled with "404, object not found" errors, placed all over the place. Does anyone know how to solve this?
Thanks,
"website.com/page.php?info=someinfo" is not a text file, this is an HTML stream.
If you want to sniff the html content resulting from the query to "website.com/page.php?info=someinfo" then you have to use file_get_contents only, not fread nor fopen.
Related
I have a web form where user needs to upload a document file (doc or docx), in that file there is some formatted data on multiple each page. so I want to extract that data but I also need to know page number as well. That means I want content of each page separately, is it possible?
Thanks
Its not in raw format, so you want this maybe to interpret the code of docx.
https://github.com/PHPOffice/PHPWord Check this.
I have a PHP script with HTML forms for user to pick several things, after that it communicates with database and prints out the result in the form of a table. Everything is formatted with CSS.
Now I would like to make those results also saved in an xls file, ideally using some sort of a "Save file" button appearing after the script finish its work. For that to work though I have to use PHPExcel write commands in several different parts of the script. But those parts are also responsible for the output on the website.
I have tried using PEAR and recently also PHPExcel and I think I can make it work with saving the file on the server, but I couldn't do it with sending to browser option (so popping up message with 'Save file as...'). When I try to do it that way, it prints out all kinds of gibberish signs on the website and doesn't pop up with save file option at all. I found out this is because I am printing and echoing all sort of things in between the PHPExcel write commands, but I am not sure how to do it differently.
So I guess my question is: Is it possible in PHPExcel or any other library to use its write commands all over the PHP script with all sort of echos and HTML code in between while using the send to browser option?
Thanks you in advance for answers and help.
I want to read the content from website and save then into a csv file in php, can anyone please tell me how I can do this.
How do you want to save a website's content as csv file? CSV means comma separated values, and it's really easy to save things as csv file but a website's content?
You say "the content from a website" - normally you'll start reading one sites content, which includes html markup, scripts and styles. Or do you only want to get the text contents or some meta data?
If your server supports opening urls via fopen I'd try this one (php.ini option: allow_url_fopen) - otherwise you'll have to use cURL or something.
Here's some more information about reading websites in php.
Regarding the storage of websites as csv I think you should be more precise what you want to achieve.
Regards, Daniel
There's no instant-magic answer for your question. We (You) need to know which website is in question, how the table is presented. If you know everything about your scenario, you should use PHP's DOM functions and parse your table then export it to a CSV.
For example, i am uploading a word file with some FORMATTED contents in the database. The content in the word document is aligned.
I done up to the above level . My issue is how can i able to view the CONTENTS AS IT LOOKS EXACTLY (means the exact formatted contents) IN A BROWSER.
Kindly help me out of this issue.
Thanks in Advance
Fero
You may stream the content in the body of the request as an attachment setting the correct MIME Type. If the user's client is configured to handle the content type it will show (after asking for permissions).
PHP MIME Content Type
Word is a format for word processing, whereas the browser is a client for displaying web pages. So no, you can't. There are some similarities between the two formats, so you can transform between them, but usually at a loss. Since Word is a proprietary format, transforming it to html can be tricky, but you can generally use open office for the job.
Another alternative is, instead of uploading the file, upload the content of the file through the use of a javascript WYSIWYG editor like TinyMCE. Since you will be storing the HTML markups that the editor converts from the formatted contents that you copy-paste in it, it will be very straight-forward to display the contents.
If the content doesn't need to be edited, why not convert it to a .PDF/.JPG on the fly, or do it once upon upload and cache the result?
In the past I have created a php file that generates the XML and then referenced it in place of the xml file and it has worked. I am trying this with a precompiled flash app and it is not working.
Any ideas why?
It works if I run the script, save it and then reference that file to the swf. I would rather not generate a file to the filesystem if possible. Anyone any solutions?
IF you pull the php page up in the browser are you sure that:
The file has no white space preceding the XML prolog (<?xml version="1.0" ... ?>)
The XML is wellformed
Another thing to check would be to look in firebug on the net panel... it shoudl show all the requests/responses made - including those done by flash (im assuming this is embedded in a web page). Look and make sure your flash is actually looking for the file you think its supposed to be looking for.
Without further information (code etc) I can only guess:
Are you trying to execute it on a server? php needs to be interpreted to generate the actual XML output, so if you don't put it on a webserver (that supports php), no content will be generated and the flash movie just sees the php code.
Check the content of the loaded php/XML file, trace it into some text field for debugging, so you can check if the actual content is being loaded correctly.
Listen for all available events of the URLLoader object. Maybe there is some IO error, you are not seeing. Alternatively you can also use the Flash debug player to see if errors are being thrown.
Also: What ActionScript version are you using?
Without seeing any of the code I would suspect the content type header isn't being set correctly and the php script is sending as html.
You can set the content type with the header funciton:
header('Content-Type: text/xml');
I'd suggest checking if some setting in your php.ini causes the output to be compressed (zlib.output_compression or ob_gzhandler).