I got a txt file and want to count the words. That's the easy part, but then i wanted also to experiment with the different cases.
For example, replace:
two or more spaces with only one if they are between words
a parenthesis between spaces with a space or a space and a parenthesis
new line with a space
etc
I used preg_replace
[PHP]$a = file_get_conten ts("$some_file" );
preg_replace('/[0-9A-Za-z][\t\t]{2,}[0-9A-Za-z]/', ' ', $a);
preg_replace('/[0-9A-Za-z][\n]{1,}[0-9A-Za-z]/', ' ', $a);[/PHP]
that example should work to replace "hello
hello" with "hello hello", "hello(space)(s pace)(space)(sp ace)(space)hell o" with "hello hello" right ???
what about the rest ???
please help...
For example, replace:
two or more spaces with only one if they are between words
a parenthesis between spaces with a space or a space and a parenthesis
new line with a space
etc
I used preg_replace
[PHP]$a = file_get_conten ts("$some_file" );
preg_replace('/[0-9A-Za-z][\t\t]{2,}[0-9A-Za-z]/', ' ', $a);
preg_replace('/[0-9A-Za-z][\n]{1,}[0-9A-Za-z]/', ' ', $a);[/PHP]
that example should work to replace "hello
hello" with "hello hello", "hello(space)(s pace)(space)(sp ace)(space)hell o" with "hello hello" right ???
what about the rest ???
please help...
Comment