2 kwi 2008

Wycięcie fragmentu tekstu zawartego miedzy tagami XML

Załadowanie XML:

$res = file_get_contents($url);

Wycięcie fragmentu tekstu:

$content_start  = strpos($res, '<content>') + strlen('<content>');
$head_end       = $content_start;
$content_end    = strpos($res, '</content>');
$foot_start     = strpos($res, '</content>');
$head    = substr($res, 0, $head_end);
$content = substr($res, $content_start, $content_end - $content_start);
$foot    = substr($res, $foot_start);
Konwersja nie zakodowanych znaków:
$content = str_replace("<",'<',$content);
$content = str_replace(">",'>',$content);
$res = $head . $content . $foot;
28 mar 2008

Odczyt i zapis pliku, wykonanie konwersji

  include 'function_convert.php'; 

  $file     = "ksero_ksero.sql";
  $file_out = "ksero_ksero_out.sql";

  $fp = fopen( $file, "r" );
  if ( $fp )  {
 
    $fw = fopen( $file_out, "w+" );

    while (!feof($fp))
    {
       $line = fgets($fp, 4096);
       fwrite($fw, UTF8toISO2($line));
    }
   
    fclose($fp);
    fclose($fw);
  }

27 mar 2008

Obliczenie czasu ładowania pliku ze wskazanego URLa

$url = 'http://www.moa.waw.pl/'

function getmicrodate(){
    $t = microtime();
    $t = explode(' ',$t);
    $total = $t[0]+$t[1];
    return $total;
}

$loadtime_before = getmicrodate();
$xml = @file_get_contents($url);
$loadtime_after = getmicrodate();
echo round(($loadtime_after-$loadtime_before),2);