GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   making sentances into words... (https://gfy.com/showthread.php?t=903370)

qwe 05-03-2009 09:03 PM

making sentances into words...
 
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?

baddog 05-03-2009 09:07 PM

and maybe eliminate any words larger then 2-3 characters? That is going to make it a pretty short list.

qwe 05-03-2009 09:11 PM

Quote:

Originally Posted by baddog (Post 15815658)
and maybe eliminate any words larger then 2-3 characters? That is going to make it a pretty short list.

not when you load up 1mb .txt file.... any know how can that be done?

d-null 05-03-2009 09:13 PM

this kind of problem is first year computer science stuff, shouldn't be too hard to find a script example out there

Iron Fist 05-03-2009 09:14 PM

Good luck to you :)

baddog 05-03-2009 09:15 PM

Quote:

Originally Posted by qwe (Post 15815668)
not when you load up 1mb .txt file.... any know how can that be done?

Maybe I am just burned out. Are you saying you want to get 1mb .txt file of words like

and
but
or
if
may
yes
to
too
she
he


and randomize them to make sentences?

qwe 05-03-2009 09:15 PM

Quote:

Originally Posted by d-null (Post 15815684)
this kind of problem is first year computer science stuff, shouldn't be too hard to find a script example out there

lol i know, but don't know jack about programming :(:helpme

qwe 05-03-2009 09:16 PM

Quote:

Originally Posted by baddog (Post 15815688)
Maybe I am just burned out. Are you saying you want to get 1mb .txt file of words like

and
but
or
if
may
yes
to
too
she
he


and randomize them to make sentences?

no, other way around.... you have a bunch of sentences and you want to make them into 1 word per line

d-null 05-03-2009 09:18 PM

Quote:

Originally Posted by qwe (Post 15815693)
no, other way around.... you have a bunch of sentences and you want to make them into 1 word per line

so no count necessary, just extract all unique words with 1, 2, or 3 characters and list them in a text file one word per line?

qwe 05-03-2009 09:20 PM

Quote:

Originally Posted by d-null (Post 15815699)
so no count necessary, just extract all unique words with 1, 2, or 3 characters and list them in a text file one word per line?

yes but all unique words EXCEPT 1/2/3 characters

ProG 05-03-2009 09:26 PM

PHP Code:

<?php
if ( ( $file file"file.txt" ) ) !== false )
{
    foreach( 
$file as $line )
    {
        
$words explode" "trim$line ) );
        foreach( 
$words as $word )
        {
            if ( 
strlen$word ) > )
            {
                echo 
$word "\n";
            }
        }
    }
}
?>


qwe 05-03-2009 09:31 PM

Quote:

Originally Posted by ProG (Post 15815716)
PHP Code:

<?php
if ( ( $file file"file.txt" ) ) !== false )
{
    foreach( 
$file as $line )
    {
        
$words explode" "trim$line ) );
        foreach( 
$words as $word )
        {
            if ( 
strlen$word ) > )
            {
                echo 
$word "\n";
            }
        }
    }
}
?>


thanks, is there anyway I can run it in windows ? sorry for stupid questions :)

ProG 05-03-2009 09:32 PM

Quote:

Originally Posted by qwe (Post 15815725)
thanks, is there anyway I can run it in windows ? sorry for stupid questions :)

WampServer.com

qwe 05-03-2009 09:45 PM

Quote:

Originally Posted by ProG (Post 15815727)
WampServer.com

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.... :helpme i'm using windows7 64bit maybe thats an issue?

ProG 05-03-2009 09:49 PM

/www is the root directory which means it would be localhost/test.php

TidalWave 05-03-2009 09:51 PM

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.

qwe 05-03-2009 09:57 PM

Quote:

Originally Posted by ProG (Post 15815753)
/www is the root directory which means it would be localhost/test.php

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 :helpme

qwe 05-03-2009 09:58 PM

Quote:

Originally Posted by TidalWave (Post 15815756)
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.

yap did that, edited it with test.txt inside test.php :helpme

ProG 05-03-2009 10:00 PM

Is the wampserver icon in the system tray all white? You only need Apache running. Click the icon, goto Apache, Restart Service

qwe 05-03-2009 10:01 PM

Quote:

Originally Posted by ProG (Post 15815765)
Is the wampserver icon in the system tray all white?

no, it's yellow but if i move mouse over it, it says server online

qwe 05-03-2009 10:04 PM

Quote:

Originally Posted by ProG (Post 15815765)
Is the wampserver icon in the system tray all white? You only need Apache running. Click the icon, goto Apache, Restart Service

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"

ProG 05-03-2009 10:06 PM

Click wampserver icon, goto Config Files, goto php.ini

Search for "memory_limit" and change the value from 8M to 128M

(You may have to restart the Apache service again)

qwe 05-03-2009 10:09 PM

Quote:

Originally Posted by ProG (Post 15815772)
Click wampserver icon, goto Config Files, goto php.ini

Search for "memory_limit" and change the value from 8M to 128M

(You may have to restart the Apache service again)

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
etc

ProG 05-03-2009 10:15 PM

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 ) > )
            {
                echo 
$word "\n";
            }
        }
    }
}
?>


qwe 05-03-2009 10:18 PM

everything worked.... thanks for your help man you rock :bowdown:)

qwe 05-03-2009 10:22 PM

btw do you have icq/skype? i might need more small scripts (next one i wont be asking for free :) )

ProG 05-03-2009 10:25 PM

np.

Just post your problems on GFY, it gives some of us something to do besides look at boobies on an "adult" message board.

ProG 05-03-2009 10:32 PM

One more revision that will give you a listing of unique words (no duplicates).

PHP 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 ) > )
            {
                if ( !
in_array$word$unique_words ) )
                {
                    
$unique_words[] = $word;
                }
            }
        }
    }
}
foreach( 
$unique_words as $word )
{
    echo 
$word "\n";
}
?>

Enjoy. Now that you have WampServer, head over to PHP.net, read the documentation and learn something :)

qwe 05-03-2009 10:33 PM

Quote:

Originally Posted by ProG (Post 15815812)
np.

Just post your problems on GFY, it gives some of us something to do besides look at boobies on an "adult" message board.

hehe yah you have a point there :) damn this i7 with 6gb of memory is killing huge txt files :pimp

qwe 05-03-2009 10:37 PM

btw that latest code you gave gives me this error "Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\test3.php on line 13" maybe file too big ?

qwe 05-03-2009 10:41 PM

yah, i down sized file like 10x smaller, and it worked.... :winkwink:

ProG 05-03-2009 10:46 PM

You know, if you have 6gb of RAM you can use it all. Change the memory_limit to 512MB or 1024MB.

qwe 05-03-2009 10:48 PM

Quote:

Originally Posted by ProG (Post 15815854)
You know, if you have 6gb of RAM you can use it all. Change the memory_limit to 512MB or 1024MB.

cool, i also switched 30seconds to 200 seconds for script execution ;>

ProG 05-03-2009 10:49 PM

Yes, that too. I usually set my localhost to 300 seconds (5 minutes).

qwe 05-03-2009 10:53 PM

Quote:

Originally Posted by ProG (Post 15815863)
Yes, that too. I usually set my localhost to 300 seconds (5 minutes).

sweet thanks again :thumbsup

qwe 05-03-2009 11:02 PM

one more thing, in php.ini should it be

memory_limit = 1024M OR memory_limit = 1024

does it need to have M at the end ? thx :winkwink:

ProG 05-03-2009 11:08 PM

I am not 100% sure but I believe it works on a system like "100K", "100M", "100G", so the "M" would be necessary. Sorry I'm a programmer not a system admin. :)

qwe 05-03-2009 11:10 PM

Quote:

Originally Posted by ProG (Post 15815893)
I am not 100% sure but I believe it works on a system like "100K", "100M", "100G", so the "M" would be necessary. Sorry I'm a programmer not a system admin. :)

gotchya, thanks

qwe 05-03-2009 11:49 PM

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)

d-null 05-04-2009 12:58 AM

Quote:

Originally Posted by qwe (Post 15815926)
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>";
           
        }
    }
}
?>


d-null 05-04-2009 01:08 AM

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

ExLust 05-04-2009 01:40 AM

Good luck!

voa 05-04-2009 02:52 AM

im not sure that something like that is exist

d-null 05-04-2009 03:26 AM

Quote:

Originally Posted by voa (Post 15816124)
im not sure that something like that is exist

http://i43.tinypic.com/o93gxl.png

Scootermuze 05-04-2009 07:28 AM

Sentances?

Might wanna incorporate a spell checker into this thing too..

Sorry.. had to be said.. :)

d-null 05-04-2009 11:09 AM

Quote:

Originally Posted by Scootermuze (Post 15816616)
Sentances?
Might wanna incorporate a spell checker into this thing too..
:)

:1orglaugh

seeandsee 05-04-2009 11:12 AM

learn word and will be easy

Killswitch - BANNED FOR LIFE 05-04-2009 11:19 AM

Quote:

Originally Posted by voa (Post 15816124)
im not sure that something like that is exist

Did you read the thread, or just post and leave?

d-null 05-04-2009 02:34 PM

Quote:

Originally Posted by Killswitch (Post 15817521)
Did you read the thread, or just post and leave?

gfy should have some kind of penalty system set up for stuff like that, like he should lose 25% of his post count for second offence or something like that :1orglaugh

Cyber Fucker 05-04-2009 02:53 PM

Quote:

Originally Posted by Killswitch (Post 15817521)
Did you read the thread, or just post and leave?

...or maybe you are bot :upsidedow


All times are GMT -7. The time now is 04:00 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc