How to read http files with php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jeanloui
Forum Commoner
Posts: 36
Joined: Fri Sep 26, 2003 2:38 pm
Location: Girona (Europe)

How to read http files with php?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:arrow: [php_man]curl[/php_man]
User avatar
jeanloui
Forum Commoner
Posts: 36
Joined: Fri Sep 26, 2003 2:38 pm
Location: Girona (Europe)

Post by jeanloui »

feyd wrote::arrow: [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.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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?
User avatar
jeanloui
Forum Commoner
Posts: 36
Joined: Fri Sep 26, 2003 2:38 pm
Location: Girona (Europe)

I'll try to explain best

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

lilPunk gave you the example you need for that.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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;
?>
User avatar
jeanloui
Forum Commoner
Posts: 36
Joined: Fri Sep 26, 2003 2:38 pm
Location: Girona (Europe)

Post 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.
:oops: 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!
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

No problem, good luck :)
Post Reply