php ?
- Started
- Last post
- 7 Responses
- versa
how can you search values of an array for specific fragments, like a year for example ....
i am a n00b here, but "in_array" and "array_search" seem to need the full, unspliced, specific value of each array element to be useful...
i want to take a bunch of data brought in from a .txt, that is divided into one liners, by carriage returns, and search through it depending what year is at the beginning of each line
- gabriel_pc0
can't you just step through the array with a foreach loop and then search each array item individually?
- versa0
well, maybe, but how can i search an individual array element for only part of a string.........ie, if the element has a year on the beginning of its value string
- cosmo0
versa, if you can show me your info. u want to parse I can come up with the code. Done it before.
- ldww0
i did this today, and used a foreach loop like suggested. but there could be a better way
- enobrev0
well, the most efficient way to do it would be to use regular expressions, althoguh it'll take you a bit to read up on them and figure them out.
If you're interested, check out preg_match and preg_match_all, and then start looking up how to write regex patterns...
This way you wouldn't even put it all into an array. You could have preg_match return the correct lines or parts of lines accordingly
As far as searching a file split into an array, I'd say the foreach is the easiest, and shouldn't be too heavy unless you're getting a few thousand hits an hour.
Ah what the hell, here's a regex example...
code:
http://dev.enobrev.com/nt/text_s…example:
http://dev.enobrev.com/nt/text_s…Good Luck!