Hi,

Solved it but there may be a more elegant/efficient way?

my code:

==============================================
<?php
$range = $_POST['range'];
$x=0;
$pc=0;
$rg = explode(",",$range);
$rc = sizeof($rg);
while( $x < $rc ){
        $z = explode("-",$rg[$x]);
        if (sizeof($z)==1){
                $pc++;
        } else {
                $pc+=(($z[1]-$z[0])+1);
        }
        $x++;
}
echo="Range has $rg groups and $pc pages<br><br>";
?>

George
> -----Original Message-----
> From: George Pitcher [mailto:[EMAIL PROTECTED]
> Sent: 29 June 2004 12:51 pm
> To: [EMAIL PROTECTED]
> Subject: [PHP-WIN] Parsing pageranges
>
>
> Hi,
>
> I have several systems running which gather, store and process
> bibliographic
> data. I have treated pageranges on the basis of two fields per
> range - start
> and end, with supplemantary ranges available as well.
>
> I've never had to deal with more than 3 ranges in a reference: chapter,
> references and notes. Now, a client has asked for 6 ranges. I could
> futureproof this by putting 10 ranges in but I got to thinking about how
> Pagemaker used to handle prining (and how Micro$oft do now) where
> I can note
> a range as (example) 1-4,6,8-10.
>
> I need to be able to parse this type of string so that I can identify the
> number of pages being referenced.
>
> I also need to ensure that the user hasn't entered a mixed range such as
> xiii-5 (I know that the second part of that is 1-5 but I don't
> know what the
> highest roman numeral was). I do know how to handle the roman
> calculations,
> so that's a side issue.
>
> I'm guessing that regex is the way to go, but whenever I'm confronted with
> it, I look for a chinese interpreter.
>
> Any suggestions?
>
>
> George in Oxford
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to