Welcome to WebmasterWorld Guest from 54.162.248.199

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Read top of Web page only

Reading part of a Web page

     
6:05 am on Oct 29, 2005 (gmt 0)

10+ Year Member



I'm using file_get_contents{URI) to read/use data in my scripts. This is urgent..

Can people here, please tell me, to read part/top of a URI? Do, you meand sockets?

I fear sockets!

Thanks to all who reply.

9:56 am on Oct 29, 2005 (gmt 0)

10+ Year Member



If you want to read part of the file that is contained within certain tags, text, or other objects in the script that will always be the same, I suggest you use something like eregi or preg_match.

For example, if you wanted to find text contained in the H1 tags you could use this code:

<?
$data = file_get_contents($uri);
if(eregi("<h1>[A-Za-z0-9.][A-Za-z0-9.]*</h1>",$data,$regs)){
echo $regs[0];
}
?>

(Anyone please correct this if any of it is wrong)

I don't use preg_match but it may be more/less useful.

Any thoughts from anyone else?

Chris

11:52 am on Oct 29, 2005 (gmt 0)

10+ Year Member



What I wanted is speed in my script.

Dumping/reading whole file, I guess, requires more time, than reading only top/part of it: if a method exits?

I didn't asked anything about preg_match

- - - - -
Every second of time, every bit of memory, every character/space of code is significant in the world of machines..

2:39 pm on Oct 29, 2005 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



what chriswragg was sayingh is that you could pull a specific portion.

You haven't told us the criteria yet. When you say top what does that mean? headers? before the body tag? the title only?

anything like file_get_contents reads the whole thing in as a string. If you want to open the connection and only read a portion then you should go with sockets.

5:28 pm on Oct 29, 2005 (gmt 0)

10+ Year Member



I'd made SEO tools for checking links to and from a Web site. It simply rely on results, I get from Google, Yahoo! and MSN.

These tools analyse more than few Web sites in a click and so go slow.

You can note, I mean to read only top of Web pages e.g., Results 1-10 of toal 23,1845.

You said sockets. Are sockets fast?
One user submitted comment on PHP online documentation on sockets say it's slow.

Can you please kindly show me an example of getting some limited data using sockets (I'm afraid of new term 'sockets'!).

Thanks.

8:20 pm on Oct 29, 2005 (gmt 0)

10+ Year Member



use curl with --max-filesize <bytes>, this will limit how many bytes you download from a page, but will not just extra the header
7:11 am on Oct 31, 2005 (gmt 0)

10+ Year Member



How to ensure curl module is enabled. I guess, most hosts won't enable it (shared hosting).

phpinfo() says ctype functions enabled. Is it mean CURL installed. Can you point me an example?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month