jeichorn's solution?

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
omega
Forum Newbie
Posts: 1
Joined: Mon Oct 06, 2003 8:21 pm

jeichorn's solution?

Post by omega »

I want to read a file from a specified position via http//. Is it possible?

I read a topic on http://php.net/fread and on the last comment it said:
For reading from a specified point in the file, use:

Code: Select all

$fp=fopen("$filename","r"); 
fseek($fp,$numpoint); 
$content=fread($fp,filesize("$filename")); 
fclose($fp);
For doing the same with an url-based file, use jeichorn@mail.com's solution and substr it. "
But there is no jeichorn@mail.com's solution on the page what I can see :(
Anyone who knows how that solution would look like? Or another way to do this?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

can't tell you what jeichorn@mail.com wrote but you might try

Code: Select all

<?php
$filename = 'http://www.php.net';

/** searching for a specific part */
$content=file_get_contents($filename); // available for (PHP 4 >= 4.3.0)
$posStart = strpos($content, '<!--UdmComment-->');
$posEnd = strpos($content, '<!--/UdmComment-->', $posStart);
$content = substr($content, $posStart, $posEnd-$posStart);
echo $content;


/** skipping a certain amount of data */
$fd = fopen($filename, 'r');

$content = fread($fd, 1045); // reading 1045 bytes 
$content = ''; // but never use them -> skipped

while(!feof($fd))
	$content .= fread($fd, 1024);

echo $content;
?>
Post Reply