Re: POSIX and PCRE help

From: Date: Sun, 17 Nov 2002 13:24:17 +0000
Subject: Re: POSIX and PCRE help
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-124792@lists.php.net to get a copy of this message
Probably none of the standard headers, but perhaps a custom header defined by the user. It's allowed for in RFC 822 and I'd like to support it. Why do you ask? Do you have a solution? "Aaron" <aaron_ott@hotmail.com> wrote in message news:20021117093106.53343.qmail@pb1.pair.com... > In what case would you have a semi-colon in the string? > > > "Orangehairedboy" <me@orangehairedboy.com> wrote in message > news:20021116151629.3787.qmail@pb1.pair.com... > > 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" <aaron_ott@hotmail.com> wrote in message > > news:20021116091753.85663.qmail@pb1.pair.com... > > > 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" <me@orangehairedboy.com> wrote in message > > > news:20021116071951.35473.qmail@pb1.pair.com... > > > > 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 > > > > > > > > > > > > > > > > > > > >

« previous php.general (#124792) next »