PHP Classes

File: example/full_example.php

Recommend this page to a friend!
  Classes of Shannon Wynter   preg_magic   example/full_example.php   Download  
File: example/full_example.php
Role: Example script
Content type: text/plain
Description: A complete example
Class: preg_magic
Extract data from text using regular expressions
Author: By
Last change:
Date: 16 years ago
Size: 894 bytes
 

Contents

Class file image Download
<?php
include_once('../preg_magic.php');

$HistoryFields = array(
   
'cardnumber' => 'card number:<\/span>\s*((?:\d{4}\s*){3}\d{4})',
   
'balance' => 'Card balance:<\/td>\s*<td>\s*(\$\d+\.\d+)',
   
'history' => array(
       
'@table' => true,
       
'@table_start' => 'class="results_table">.+?<\/tr>\s*',
       
'@table_end' => '\s*<\/table>',
       
'@table_fields' => array(
           
'stamp' => '\s*<tr class="(?:odd|even)">\s*'
                             
. '<td>(\d+-\w+-\d+\s*\d+:\d+\s*\w+)<\/td>',
           
'type' => '<td.*?>\s*([^<]*?)\s*<\/td>',
           
'location' => '<td.*?>\s*([^<]*?)\s*<\/td>',
           
'amount' => '<td.*?>\s*([^<]*?)\s*<\/td>',
           
'gst' => '<td.*?>\s*([^<]*?)\s*<\/td>\s*<\/tr>\s*'
       
)
    )
);

$HistoryHTML = preg_replace("/\s\s+|&nbsp;/",' ',file_get_contents('history.html'));

$Output = preg_magic::execute($HistoryFields, $HistoryHTML);

print_r($Output);