Forum Moderators: coopster
Vince: If our friend is storing over a megabyte of data that needs to be parsed later with two delimiters... The overhead of two passes is the least of his worries :-)
However, if two passes makes you unhappy, use a preg split to split based on - or spaces... One pass, simplified logic of a split. This would be faster than running your own code to parse char by char, no?
26 2- 4 2- 2 0- 2 0- 3 2 1 0 1 2 6is space-delimited. Did you mean tab delimited?
Is there anyway you can load data that is not comma or space delimited into a table?
abs function:
$columns = explode(' ', '26 2- 4 2- 2 0- 2 0- 3 2 1 0 1 2 6');
// or, if trying to match ALL whitespace characters:
$columns = preg_split ("/[\s]+/", '26 2- 4 2- 2 0- 2 0- 3 2 1 0 1 2 6');
while (list($key, $value) = each($columns)) {
$columns[$key] = abs($value);
}
Lorax: This method doesn't make sense to me... I haven't tested but I'm fairly sure the processor load/time would be larger than two non preg splits.
I said it would work but I didn't say it was elegant. ;)
The need for more efficiency depends upon how many or how large the string is. If we're talking about a one time event or a modest amount of data it doesn't really matter that much. There's more than one way to achieve the end result.
If, however, we're talking about an ongoing need to parse large strings - yes, it would be wise to write more efficient code.
I did mean TAB delimited, not space, sorry for the confusion.
I would like to build an admin tool where I can add a row of data such as this and have it upload properly. Would this be possible?
What this dat is, is a line of stats from a basketball boxscore. On a daily basis I want to add such a line for each player who played. My plan is to have an admin tool where I can search by team, all of the players for that team will display, and I can add these lines for each player and then hit SUBMIT.