News:

Wondering if this will always be free?  See why free is better.

Main Menu

fopen and point selection

Started by Les Mackenzie, May 10, 2004, 03:17:48 PM

Previous topic - Next topic

Les Mackenzie

Does anyone know if it's possible to fopen a URL and select a certain line or range of lines in the file?  Not the beginning or end, say somewhere in the middle like a predefined line of text etc.?

I'm working on a script that converts html to xml but it only converts to whole file and not a ranged portion...  for example I want to select line 256 to 358 nothing before or after predetermined lines.

Many Thanks  :D
BLOGS SUCK! - HERE READ MINE

Please Note:  Arguing on the internet is like running in the Special Olympics...  Even if you win you're still retarded.

[Unknown]

If you use the file() function, you can get a slice of it with array_slice().

-[Unknown]

Les Mackenzie


<?php

$lines  
=  file('http://www.website.com');

$date   = mktime(0,0,0,date('m'), date('d'), date('Y'));
$day    = date('d', $date);
$month  = date('m', $date);
$year   = date('y', $date);

$findme = $day.$month.$year;
$start  = 0;
$t      = '';
$position = 0;


foreach (
$lines as $line_num => $line) {
 

  if (
strpos($line, $findme))
  {


//$t = $t.htmlspecialchars($line);

$t = $t.$line;

$start = $start + strlen(trim($line));

  }

}
$position = strrpos($t, $findme);

$htmlfile = substr($t, 2620, ($position-2620)+100);
 

$filename = "protemp.txt";
$new_file = fopen ($filename, "w") or die("Could not open file");
fwrite($new_file, $htmlfile);
fclose($new_file);

$filename2= "News.html";
 

$fh = fopen ($filename, "r") or die("Could not open file");
 
$final = fopen ($filename2, "w") or die("Could not open file");
$font = '<font size="1" face="Verdana, Arial, Helvetica, sans-serif">';

 while (!
feof($fh))
 {
 
$data = fgets($fh, 1000);
 if (
trim($data) != "")
 {
 
$htmldata =  $data;
 echo
$htmldata;
 
fwrite($final, $htmldata);
 }
 }
 
fclose ($fh);
 
fclose ($final);
?>


It works...  that is all.  Thanks for the tip  :)
BLOGS SUCK! - HERE READ MINE

Please Note:  Arguing on the internet is like running in the Special Olympics...  Even if you win you're still retarded.

Advertisement: