In what case would you have a semi-colon in the string?

"Orangehairedboy" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Aaron,
>
> Thanks for the advise, but I'm got a problem. If I first split it up by
/;/,
> how do I catch it if there's a semi-colon inside a string?
>
> Lewis
>
>
> "Aaron" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Lewis,
> >
> > First I would look at breaking out the tags:
> >
> >     // User: JohnDoe; age=32; nickname="Billy 'the' Kid";
> haircolor=orange;
> >
> >     $string = 'User: JohnDoe; age=32; nickname="Billy \'the\' Kid";
> > haircolor=orange;';
> >     $stringArray = preg_split('/;/', $string, -1, PREG_SPLIT_NO_EMPTY);
> >
> > Then split by the = or :
> >
> >     // split by = or :
> >
> >     foreach ($stringArray as $item) {
> >         list($tag, $element) = preg_split('/\:|\=/', $item, 1,
> > PREG_SPLIT_NO_EMPTY);
> >         echo "$tag => $element<br />";
> >     }
> >
> > -aaron
> >
> > "Orangehairedboy" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > I am trying to learn more about regular expressions as I haven't used
> them
> > > much in the past. I am working with email, and I'm looking for a way
to
> > > split the following expression up:
> > >
> > > Content-Type: text/plain; boundary="whatever";
> > >
> > > Using   "/^(\S+)\:\s*(.+)$/iU"   I can split it into:
> > >
> > > [Content-Type] and [text/plain; boundary="whatever";]
> > >
> > > Problem is, it might have different tags. Here's a sketch of the whole
> > > thing:
> > >
> > > [Header Name a-zA-Z0-9] [\s*] [:] [\s*] [ Header value a-zA-Z0-9/_ ]
> [\s*]
> > > [;] [ unlimited repeating pattern of ( [Property Name a-zA-Z0-9] [\s*]
> [=]
> > > [\s*] ( string optionally surrounded by quotes - but necessary if
value
> > has
> > > spaces - but can't include quotes ) [\s*] [;] ) ]
> > >
> > > So, if I had:
> > >
> > > User: JohnDoe; age=32; nickname="Billy 'the' Kid"; haircolor=orange;
> > >
> > > I would need:
> > >
> > > User - "JohnDoe" - age - "32" - nickname - "Billy 'the' Kid" -
> haircolor -
> > > "orange"
> > >
> > > in the outputted array. I have no idea how to do repeating patterns
like
> > > this...maybe I'm making this too complex?
> > >
> > > Thanks for your help!
> > >
> > > Lewis
> > >
> > >
> >
> >
>
>



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

Reply via email to