A way to escape a comma?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yanisdon
Forum Newbie
Posts: 18
Joined: Thu Jul 06, 2006 10:44 pm

A way to escape a comma?

Post by yanisdon »

Hi there,
Just a quick q:

Is there a way to escape a comma- possibly with a fancy regex or something?

Cheers
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Escape a comma in what context..?
yanisdon
Forum Newbie
Posts: 18
Joined: Thu Jul 06, 2006 10:44 pm

Post by yanisdon »

A little bit of background-info:
I wrote a little app using Magpie to parse a RSS/XML file into an array.
One field of that array is getting filled with 'taxonomy terms'. Sometime those terms are containing comma's (E.g. "Folksonomy, multiple Taxonomies combined"). Alas my app doesn't like that programmatically wise, because I am using a function to comma-separate terms :)

This unfortunately will render the term in question into the two new terms: "Folksonomy" and "multiple Taxonomies combined".

Cheers.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Normally when the character used as a delimeter is found within the string, the string is wrapped in quotes.

Check out the user comments on how to parse csv strings
User avatar
Josh1billion
Forum Contributor
Posts: 316
Joined: Tue Sep 11, 2007 3:25 pm

Post by Josh1billion »

Hmm.. strange idea I have but what if you do a backwards escape? I.e., instead of using "," as the glue holding your string pieces together, why not use "\," (or some other rarely-typed string) as the parsing glue? Then you'll only run into problems if the user decides to type "\," into field.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I would first consider changing my delimiter to something less common then a comma, like [--delimiter--]

What are the chances anyone would tag something that?

@aaronhall: I just got your avatar... priceless!
yanisdon
Forum Newbie
Posts: 18
Joined: Thu Jul 06, 2006 10:44 pm

Post by yanisdon »

Yeah, actually that's pretty close to what I was thinking as well.

However, is there a way to escape a comma?

There must be some creepy regex out there. Am stoked to learn about that..
User avatar
Josh1billion
Forum Contributor
Posts: 316
Joined: Tue Sep 11, 2007 3:25 pm

Post by Josh1billion »

Kieran Huggins wrote:I would first consider changing my delimiter to something less common then a comma, like [--delimiter--]
That's what I meant.. ;)
Post Reply