preg_magic: Extract data from text using regular expressions

Recommend this page to a friend!
  Info   View files (17)   Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
74%Total: 1,404 All time: 2,756 This week: 410
Version License PHP version Categories
preg_magic 1GNU General Publi...5PHP 5, Text processing
Description Author

This class can be used to extract data from text using regular expression patterns.

It takes an array of regular expressions that define the patterns to match and extract data.

An entry of the expressions array may be another array that defines patterns of repetitive sections that must be iterated to extract data from each of the repeated sections, like for instance HTML tables with sections of the rows of cell data.

The extracted data patterns is returned in associative arrays.

Innovation Award
PHP Programming Innovation award nominee
February 2008
Number 7


Prize: One downloadable copy of Komodo Pro
Regular expressions are often used to extract information from different types of text documents.

Sometimes it is necessary to extract information that appears with the same format in multiple sections of a document, like for instance, text that is presented in multiple rows of HTML table. Extracting data from this kind document may require the use of multiple types of regular expressions.

This class provides a solution to simplify the extraction of text from document with repetitive sections by iterating through a set of given regular expressions.

Manuel Lemos
Picture of Shannon Wynter
Name: Shannon Wynter is available for providing paid consulting. Contact Shannon Wynter .
Classes: 9 packages by
Country: Australia Australia
Age: 38
All time rank: 1232 in Australia Australia
Week rank: 713 9 in Australia Australia
Innovation award
Innovation award
Nominee: 3x

Details
preg_magic
-------------------

Version 1.0

Author: Shannon Wynter (http://fremnet.net/contact)
		Copyright Shannon Wynter & Fremnet.net

Licence: GPL 2.0

Class/Function to assist with parsing great piles of garbage (ie: HTML) into nice
hashes/associative arrays with a few regular expressions.

Basic Synapsis:
-------------------

preg_magic($Fields, $Target)

$Fields is an associative array that contains the structure you
expect to extract from the file.

It is very important to understand that you must supply the fields
in the order that you expect them to be matched.

There are currently two types of fields
 - simple
 - table

A simple field is simply defined as 'name' => 'expression to match'

A table field is a whole lot more complicated but it's also very
flexable, and is defined as follows:

 '@table'       => true,
 '@table_start' => 'the expression to match at the start of the table',
 '@table_end'   => 'the expression to match at the end of the table',
 '@table_fields => array(of more fields),

Both @table_start and @table_end will be ignored if this is the
root element of the array.

So an example structure might look like the example file
example/fields_example.php - This example shows two simple fields,
and a table

The structure can be recursive, ie, you can have more table and
simple fields beneith the table field

A full example can be found in example/full_example.php

Full Documentation:
-------------------

You can generate full documentation by making sure you have
phpDocumentor installed and running the document.sh file found in
this directory

License:
-------------------

This library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
  Files  
File Role Description
doc (7 files, 2 directories)
example (3 files)
document.sh Data Documentation Generator
preg_magic.php Class Main class/function file
README Doc. Readme file

  Files  /  doc  
File Role Description
media (2 files)
preg_magic (2 files)
   blank.html Doc. Documentation
   classtrees_preg_magic.html Doc. Documentation
   elementindex.html Doc. Documentation
   elementindex_preg_magic.html Doc. Documentation
   index.html Doc. Main Documentation Index
   li_preg_magic.html Doc. Documentation
   packages.html Doc. Documentation

  Files  /  doc  /  media  
File Role Description
   banner.css Data CSS for Documentation
   stylesheet.css Data CSS for Documentation

  Files  /  doc  /  preg_magic  
File Role Description
   preg_magic.html Doc. Documentation
   _preg_magic.php.html Doc. Documentation

  Files  /  example  
File Role Description
   fields_example.php Example An example fields layout
   full_example.php Example A complete example
   history.html Data Example data

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,404
This week:0
All time:2,756
This week:410
User Ratings User Comments (1)
 All time
Utility:91%
Consistency:91%
Documentation:91%
Examples:100%
Tests:-
Videos:-
Overall:74%
Rank:177
 
thank you for you word.
12 years ago (webcgo)
80%
 

For more information send a message to info at phpclasses dot org.