On Tue, 2010-01-26 at 07:56 -0500, Al wrote:

> 
> On 1/25/2010 10:48 PM, Camilo Sperberg wrote:
> > Hello list :)
> >
> > I have this problem, a certain string can contain the following information:
> >
> >
> > $string = '
> > hi{value1;value2}
> > bye{value1;value3}
> > hi{value1;value4}
> > hi{value1;value2}
> > bye{value1;value2}
> > ';
> >
> > What I want is to be able to get this result:
> >
> > $string = '
> > hi{value1;value2}
> > bye{value1;value3}
> > hi{value1;value4}
> > bye{value1;value2}
> > ';
> >
> > (the order of appearance doesn't matter)
> > Is it even possible to do this with regular expressions? Or should I first
> > look if there is some kind of match and then apply an
> > str_replace($match,'',$string) and add the $match again?
> >
> > Greetings !
> >
> 
> Assuming the duplicate segments are identical.....
> I'd use explode() and convert the string to an array. Use "}" for the 
> delimiter.
> Then use array_unique()
> And then use implode() to restore the string.
> 
> 
> 


Just did a bit of hunting as I know I've seen something similar to what
you're asking before.

If you're on a Linux system, try this:

awk '!x[$0]++' inputfile > outputfile

This seems to be the best way to remove duplicate lines and still
preserve the original order of the unique lines.

Thanks,
Ash
http://www.ashleysheridan.co.uk


Reply via email to