Merge all post data with comma separators?

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
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Merge all post data with comma separators?

Post by JAB Creations »

Situation: User posts large amounts of data that will be used as CSS values (later on) to the server.

Goal: I'd like to merge all post the data in to a single string, separate each piece of post with a comma, and then check the data using regex for some simple patterns. The order does not necessarily matter but that is the way I am initially approaching it. Once complete this single string will be set to a cookie. To my site's visitor this information will be used in a second style sheet that overrides the primary style sheet which will use PHP to later split data in to an array and construct the secondary stylesheet. (You guys are going to drool when you see my new site editor. :mrgreen:)

The data construct is fairly simple and repetitive...

1.) User selects a selector (range 0-24).
2.) User selects a property (range 0-3).
3.) User selects a value (three characters 0-f || six characters 0-f || 'none' || 'transparent').

The input names are based on the select[] index.
'ce' + selector[] + property[] = value.

Examples...
Selector 9, property 4 = 'ce83' (value is changed to selected value)
Selector 10, property 3 = 'ce92'
Selector 11, property 2 = 'ce101'
Selector 12, property 1 = 'ce110'

Keep in mind that the select index starts at 0 so...
you think 1 and it's 0...
you think 2 and it's 1...
you think 3 and the index is 2 etc.

This is how the data is structured being sent to the server. Maybe it could be handled by the client but we can't trust the client can we? I am open to the idea of merging the data to a single string at the client though I'd still have to run regex checks at the server regardless.

Any way to reduce server load I use a hidden input to tell the server what form is being used. In my mind at least this skips PHP from executing all of the code I will/we'll be working on here if the request isn't a post method and if it is will only execute in the following condition...

Code: Select all

if ($_POST['formis'] == "site_editor")
{
 
}
My Questions essentially barrel down to...
1.) Would it be better to merge all the data in to a single string at the server or the client? By default I have been planning to do this at the server.

2.) I already run regex at the client though would it be easier to do regex on a single string or a temporary array? For example the value 'none' would be allowed on every second of four sets of values while color (0-f) values of three or six characters in length or the value 'transparent' would be allowed via the regex every first, third, and fourth value out of every set of four.

I'm very interested in your opinions to help me create a Titan instead of a Frankenstein. :mrgreen:
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Merge all post data with comma separators?

Post by Jade »

1) PHP is a server side scripting program. That means any kind of php you run will be server side. If you wanted to run this client side you'll have to use javascript. Personally, if you're just putting commas between everything then I'd do it with javascript since there's not much to it and you can have it concatenate the string as the user is inputting the data.

2) I'm not i'm regex guru, I actually almost never use it so I'm afraid my input here won't be of much help. Although I will say I've never seen regex run on an array before but since I don't use it I couldn't tell you either way.
Post Reply