Jump to content

Read a complex file ....


pincopallo_it

Recommended Posts

What I have to do is to read a file, more precisely an html file.

I have to read that file couse I need to use some information are written inside.

The html is attached. What I need to extract is the dates and the times you can read inside the html as I have to calculate the worked hours from there.

I tried reading the file line by line :

$file = fopen($newname, "r") or exit("Unable to open file!");

 

while (!feof($file))

{

 

$linea =  fgets($file);

echo $linea; // pubblica la intranet

 

 

//$pos = strpos($linea, 'font face=arial size=2');

//echo $pos;  // situazione della font face

 

  }

 

but that strpos did not work ...

Who has an idea ? .... hope I was clear enough ...

Thanks

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/109933-read-a-complex-file/
Share on other sites

a simple solution:

<?php
$file = "file.html"; //change this to point to the file.
$fh = fopen($file, "r");
$code = fread($fh, filesize($file));
$code_array = explode("\n", $code);
foreach ($code_array as $value){
if (strstr($value, "font face=arial size=2")){
	$new_array[] = $value;
}
}
print_r($new_array); //this just shows you the output. you can remove this, and in its place, take the data and manipulate it to your hearts content (the array, that is).

Link to comment
https://forums.phpfreaks.com/topic/109933-read-a-complex-file/#findComment-564118
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.