is there a way to let's say load up a .txt file with a bunch of lines of text and extract all the words as a list 1 word per line ? and maybe eliminate any words larger then 2-3 characters?
making sentances into words...
Collapse
X
-
this kind of problem is first year computer science stuff, shouldn't be too hard to find a script example out there
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
Comment
-
Comment
-
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
-
PHP Code:<?php if ( ( $file = file( "file.txt" ) ) !== false ) { foreach( $file as $line ) { $words = explode( " ", trim( $line ) ); foreach( $words as $word ) { if ( strlen( $word ) > 3 ) { echo $word . "\n"; } } } } ?>History will be kind to me for I intend to write it.Comment
-
thanks, is there anyway I can run it in windows ? sorry for stupid questions
Comment
-
sorry, i installed it and what do I do next ? i put that test.php into C:\wamp\www and go to http://localhost/phpmyadmin/test.php and page is blank....
i'm using windows7 64bit maybe thats an issue?
Comment
-
edit the filename to the one of the txt you already have.
make sure the file is in the same directory as your php script.Comment
-
yah I tried that... i put test.php and test.txt into www folder under C:\wamp\www and when i go to http://localhost/test.php nothing happens just a blank white page in firefox, in explorer says page can't be found... says wampserver is online, it also has index.php in the www folder as well (it came with it) and that page doesn't load either hrmmmm
Comment
-
ok figured it out, skype was using port 80, ok apache started and looks like it tried to execute your code, and came up with an error "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in C:\wamp\www\test.php on line 2"Comment
-
ok it was already at 128mb, anyways i made file smaller and it worked but all the words are on the same line, not 1 word per line... also they include dots, comas and " ' anyway to get rid of them? here's what it displays now:
morning, stay same room keep watch shifts, never more than three asleep time. Hirschel asked. believe. doesn't have windows. angry Cyr's put-down, Jubal said, windows? What does that matter? killer said. still ruling other possibilities. Besides looking each you, don't want have guard windows. Hirschel said,
suppose to be :
morning
stay
same
room
etc
etcLast edited by qwe; 05-03-2009, 09:10 PM.Comment
-
If you right click and View Source it will not be on one line. Otherwise, replace "\n" with "<br>" for html output.
Revised code to remove extra chars.
PHP Code:<?php if ( ( $file = file( "file.txt" ) ) !== false ) { foreach( $file as $line ) { $words = explode( " ", trim( $line ) ); foreach( $words as $word ) { $word = ereg_replace( "[^A-Za-z0-9]", "", $word ); if ( strlen( $word ) > 3 ) { echo $word . "\n"; } } } } ?>History will be kind to me for I intend to write it.Comment
-
One more revision that will give you a listing of unique words (no duplicates).
Enjoy. Now that you have WampServer, head over to PHP.net, read the documentation and learn somethingPHP Code:<?php $unique_words = array( ); if ( ( $file = file( "file.txt" ) ) !== false ) { foreach( $file as $line ) { $words = explode( " ", trim( $line ) ); foreach( $words as $word ) { $word = ereg_replace( "[^A-Za-z0-9]", "", $word ); if ( strlen( $word ) > 3 ) { if ( !in_array( $word, $unique_words ) ) { $unique_words[] = $word; } } } } } foreach( $unique_words as $word ) { echo $word . "\n"; } ?>
History will be kind to me for I intend to write it.Comment
-
hey ProG, anyway you can make me another simple script? to check for any empty lines and lines that start with 0-9 or some weird symbols (such as -,---,===,%---, etc, etc) and remove those lines ?
basically to remove any empty lines and lines that start with anything other then a valid character (a-z or A-Z)
Last edited by qwe; 05-03-2009, 10:52 PM.Comment
-
hey ProG, anyway you can make me another simple script? to check for any empty lines and lines that start with 0-9 or some weird symbols (such as -,---,===,%---, etc, etc) and remove those lines ?
basically to remove any empty lines and lines that start with anything other then a valid character (a-z or A-Z)
if I understand what you are asking for, this will do it nicely:
Code:<?php if ( ( $file = file( "file.txt" ) ) !== false ) { foreach( $file as $line ) { if (ctype_alpha($line{0})) { echo $line . "<br>"; } } } ?>
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
also note that I used <br> for html output instead of \n so if you need it for your text file use then you should change that part
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
-
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
Sentances?
Might wanna incorporate a spell checker into this thing too..
Sorry.. had to be said..
Comment
-
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
__________________
Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs
Check out the #1 WordPress SEO Plugin: CyberSEO SuiteComment
-
Comment



BUY MY SIG - 50$/Year
Comment