Ashura: html title einer url per php auslesen

Beitrag lesen

Hallo Gunnar™

Kleine Korrektur für den Fall, der eigentlich nicht auftreten darf:

<?php  
  
$str_html = '<html><head><title>Foo</title></head><body><p>Bar</p></body>'; // Simples HTML-Dokument  
$int_start = [link:http://de2.php.net/manual/en/function.strpos.php@title=strpos]($str_html, '<title>'); // Position des title-Anfangstags  
  
if ($int_start !== false) {  
  
  $int_start += 7; // [link:http://de2.php.net/manual/en/function.strlen.php@title=strlen]('<title>') == 7  
  $int_end = strpos($str_html, '</', $int_start); // Position des title-Endtags  
  
  echo [link:http://de2.php.net/manual/en/function.substr.php@title=substr]($str_html, $int_start, $int_end - $int_start); // „Foo“  
  
}  
  
?>

Eigentlich _muss_ immer ein title-Element vorhanden sein. Eigentlich.

Einen schönen Sonntag noch.

Gruß, Ashura

--
sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
„It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
[HTML Design Constraints: Logical Markup]