WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Parse html (title :: meta)
Categories : PHP, HTML and PHP, Regexps Click here to Update Your Picture
Olaf Lederer
Date : Dec 03rd 2005
Grade : 3 of 5 (graded 2 times)
Viewed : 22491
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Olaf Lederer
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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;
    }
}
?>



php table decoder used to convert an html table to individual tokens through regular expressions
Categories : PHP, Regexps, HTML and PHP
Form input return conformance
Categories : HTML and PHP, PHP, Regexps
PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
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
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
PHP Newline Functions
Categories : PHP, HTML and PHP, Regexps
Parsing Simple Template Files and Data
Categories : PHP, PHP Classes, Templates, Regexps
Match words that are entered into a <textarea> in any layout orientation (horizontal, vertical, diagonal).
Categories : PHP, Regexps
What is the best way to split a string that consists of two bits of data seperated by whitespace?
Categories : Regexps, Strings, PHP
Reduce PHP/HTML File Sizes
Categories : PHP, Compression, HTML and PHP, Zlib
phpAddQuote v1.2 - UPDATED! Lets users add their own quotes to your website. You specify how many quotes appear on the page at a time. Easier install!
Categories : HTML and PHP, Complete Programs, PHP, Databases, Personalization and Membership
Pseudo Non Parsed Header. Output to the the browser as the script runs.
Categories : PHP, HTTP, HTML and PHP
Simple PHP control CSS Calendar
Categories : PHP, HTML and PHP, Calendar, Date Time, CSS
phpWebCam v1.0- Webcam management software - Automatically checks if you're online, and comes with a caption tool capable of handling multiple users.
Categories : PHP, Complete Programs, HTML and PHP