Re: Find Strings (Tokens) in File and push them into an array - How? [message #169618 is a reply to message #169606] |
Sun, 19 September 2010 10:30 |
aaaa
Messages: 7 Registered: September 2010
Karma:
|
Junior Member |
|
|
> The code could even be shortened a bit. My version would be:
>
> foreach ($files as $file) {
> $text = file_get_contents($file);
> preg_match_all('/\$__txt.+?;/', $text, $matches);
> $tokens = array_merge($tokens, $matches[0]);
> }
foreach ($files as $file) {
$text = file_get_contents($file);
$matches = explode(' ', $text);
$tokens = array_merge($tokens, $matches);
}
Same result, but easier (and shorter!) code. And I can even make it shorter:
foreach ($files as $file) {
$text = file_get_contents($file);
$tokens = array_merge($tokens, explode(' ', $text));
}
Or even shorter:
foreach ($files as $file) {
$tokens = array_merge($tokens, explode(' ', file_get_contents($file)));
}
And it's still clearer code then your reg.exp.
--
A
|
|
|