Try split() function which splits a string into an array based on a regular expression (PP manual) : this is different than explode() which splits on a fixed delimiter.

eg (this is in the manual ):
$stringparts=split ('[,-]', $string);

Will split $string= "1,3, 3-6, 8" into individual array elements. Don't forget to remove spaces from the input first, str_replace(" ","",$string) or add spaces as a non-separator to your regex.

Then use array_unique(array,array) to remove duplicates. Don't you just *love* PHP :-)

Finally recombine the array in your desired format (I have no idea what rules the 'correct form' takes - you have to write that yourself :-)

Cheers,
Neil Smith.


At 15:15 04/02/2003 +0000, Bobo wrote:
Message-ID: <000901c2cc35$23fbe940$9df81e0a@elstudion>
From: "Bobo Wieland" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Date: Tue, 4 Feb 2003 11:06:37 +0100
MIME-Version: 1.0
Content-Type: text/plain;
        charset="Windows-1252"
Content-Transfer-Encoding: 7bit
Subject: Difficult String/number fomatation plz hlp!

Hi!

I have a textfield wich allows any number of integers seperated with " ",
"," or "-"...

I need this input to be formated in two steps:
First into a sequence of numbers into an array, lowest first... Second to
the correct form of the initial input...

Example:

User input: "1,3, 3-6, 8" (string)
First step: 1,3,4,5,6,8 (array)
second step: "1,3-6,8" (string)

please help me with this one! I don't mind using ereg-functions though I'm
not good at it myself...

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

Reply via email to