|
|
|
With this script it's possible to obtain the first part of a remote file to parse the html elements in local script. The title element, the meta description and the meta keywords are parsed while using eregi() function. Additional meta elements are possible, by adding some extra rules and regex patterns. The script reads only the first part of a remote file, until the closing tag of the html head element is passed, the result is a better performance. The script will not follow url redirections. This script is very usefull in forms to add new links to a linklist. Version 1.01: the script works now also for pages with XHTML styled code.
| <?php
$page_title = "n/a";
$meta_descr = "n/a";
$meta_keywd = "n/a";
if ($handle = @fopen("http://www.finalwebsites.com", "r")) {
$content = "";
while (!feof($handle)) {
$part = fread($handle, 1024);
$content .= $part;
if (eregi("</head>", $part)) break;
}
fclose($handle);
$lines = preg_split("/\r?\n|\r/", $content); // turn the content in rows
$is_title = false;
$is_descr = false;
$is_keywd = false;
$close_tag = ($xhtml) ? " />" : ">"; // new in ver. 1.01
foreach ($lines as $val) {
if (eregi("<title>(.*)</title>", $val, $title)) {
$page_title = $title[1];
$is_title = true;
}
if (eregi("<meta name=\"description\" content=\"(.*)\"([[:space:]]?/)?>", $val, $descr)) {
$meta_descr = $descr[1];
$is_descr = true;
}
if (eregi("<meta name=\"keywords\" content=\"(.*)\"([[:space:]]?/)?>", $val, $keywd)) {
$meta_keywd = $keywd[1];
$is_keywd = true;
}
if ($is_title && $is_descr && $is_keywd) break;
}
}
?> | | |
|
| Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Form input return conformance Categories : HTML and PHP, PHP, Regexps | | | php table decoder used to convert an html table to individual tokens
through regular expressions Categories : PHP, Regexps, HTML and PHP | | | How to use regular expressions to get the list of links from an HTML page Categories : PHP, Regexps, HTML, HTML and PHP | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Check if a file exists on a remote FTP server with PHP Categories : PHP, FTP, Regexps | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS) | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | |
|
|
|