Page 1 of 1
How to read http files with php?
Posted: Thu Jul 29, 2004 11:29 am
by jeanloui
I would like an script capable of reading files using http.
I have tried "readfile" and "fopen" and it didn't wor for me (those only read "files", not the http parsed code).
(I think is not a problem of "allow_url_open" permissions, cause I only need to read the html parsed info).
What I really need is some script that can read the html parsed code from a php (or mere html) file or URL in the net.
Then I could filter it, and extract -filter- some information from the "readed" html.
---------
All suggestions are really welcome.
To more detailed sugestions, I will share my project (about PostNuke atomated update)
-----
Thanks
jeanloui
http://imagicweb.com
Posted: Thu Jul 29, 2004 11:31 am
by feyd

[php_man]curl[/php_man]
Posted: Thu Jul 29, 2004 11:57 am
by jeanloui
feyd wrote:
[php_man]curl[/php_man]
I'll try curl, but it seems to need some special php install (and I need reading also html "http" parsed code):
Code: Select all
"Once you've compiled PHP with CURL support, you can begin using the CURL functions (---)"
Also an small example can help a lot.
Thanks.
Posted: Thu Jul 29, 2004 12:16 pm
by Buddha443556
jeanloui wrote:Also an small example can help a lot.
Totally off topic but has any notice the comments are gone from PHP manual? Those comments had many helpful examples.
What's left?
Sockets?
Posted: Thu Jul 29, 2004 1:03 pm
by d3ad1ysp0rk
err..
index.php
Code: Select all
<?php
$a = 1;
$b = 2;
echo $a+b . " = a + b!";
?>
file_test.php
Code: Select all
<?php
$contents = file_get_contents("http://mysite.com/index.php");
echo $contents;
?>
would echo 3 = a + b, not the php code, so what's the issue?
I'll try to explain best
Posted: Thu Jul 29, 2004 1:47 pm
by jeanloui
LiLpunkSkateR wrote:err..
err..
This begins to work, but...
It's suposed that an html or php file called from http produces something like:
Code: Select all
<html>
<body>
hello
</body>
</html>
How can I read from a php script the full text (I mean the http parsed TEXT).
I need an script that echoes:
Code: Select all
<html>
<body>
hello
</body>
</html>
being the file called a simple html file or a php producing html.
There I could (I will) filter all the text (avoiding or including TAGS) and extract some concrete information of the parsed html text.
Posted: Thu Jul 29, 2004 1:58 pm
by feyd
lilPunk gave you the example you need for that.
Posted: Thu Jul 29, 2004 3:37 pm
by d3ad1ysp0rk
It does print that.. viewing it in the browser however shows you the result (the HTML parsed). If you view the source, it's exactly what you want.
Anyways, I kinda see what you're getting at.. but.. you're gonna need more than this to pull the info (more string functions or a regex pattern):
Code: Select all
<?php
$contents = file_get_contents("http://mysite.com/index.php");
$contents = str_replace("<","<",$contents);
$contents = str_replace(">","&rt;",$contents);
echo $contents;
?>
Posted: Fri Jul 30, 2004 5:24 am
by jeanloui
LiLpunkSkateR wrote:It does print that.. viewing it in the browser however shows you the result (the HTML parsed). If you view the source, it's exactly what you want.

Ah! I understand now!
... you're gonna need more than this to pull the info (more string functions or a regex pattern)
Yes, I know but I think this is exactly what I was needing to begin filtering!
Thank you very much!
Posted: Fri Jul 30, 2004 7:44 am
by d3ad1ysp0rk
No problem, good luck
