1<?php 2/* 3Released through http://bibliophile.sourceforge.net under the GPL licence. 4Do whatever you like with this -- some credit to the author(s) would be appreciated. 5 6A collection of PHP classes to manipulate bibtex files. 7 8If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net 9so that your improvements can be added to the release package. 10 11Mark Grimshaw 2005 12http://bibliophile.sourceforge.net*/ 13/***** 14* PARSEPAGE: BibTeX PAGES import class 15*****/ 16class PARSEPAGE 17{ 18// Constructor 19 function PARSEPAGE() 20 { 21 } 22// Create page arrays from bibtex input. 23// 'pages' field can be: 24// "77--99" 25// "3 - 5" 26// "ix -- 101" 27// "73+" 28// 73, 89,103" 29// Currently, PARSEPAGE will take 1/, 2/ and 3/ above as page_start and page_end and, in the other cases, will accept 30// the first valid number it finds from the left as page_start setting page_end to NULL 31 function init($item) 32 { 33 $item = trim($item); 34 if($this->type1($item)) 35 return $this->return; 36// else, return first number we can find 37 if(preg_match("/(\d+|[ivx]+)/i", $item, $array)) 38 return array($array[1], FALSE); 39// No valid page numbers found 40 return array(FALSE, FALSE);; 41 } 42// "77--99" or '-'type? 43 function type1($item) 44 { 45 $start = $end = FALSE; 46 $array = preg_split("/--|-/", $item); 47 if(sizeof($array) > 1) 48 { 49 if(is_numeric(trim($array[0]))) 50 $start = trim($array[0]); 51 else 52 $start = strtolower(trim($array[0])); 53 if(is_numeric(trim($array[1]))) 54 $end = trim($array[1]); 55 else 56 $end = strtolower(trim($array[1])); 57 if($end && !$start) 58 $this->return = array($end, $start); 59 else 60 $this->return = array($start, $end); 61 return TRUE; 62 } 63 return FALSE; 64 } 65} 66?> 67