Jump to content

Filtering Input


N-Bomb(Nerd)

Recommended Posts

I need some help filtering input from file1.txt to file2.txt. I've been trying for about the last 6-7 hours to make this script and failing horribly. What I'm looking to have my script do is open file1.txt and remove all non-alpha characters. Then as it's writing to file2.txt it will replace all spaces with newlines..

 

Example:

File1.txt reads:

Th1e do2dgers wo4n t3he b6ase2ba43ll ga#%!me!

 

After the script is ran File2.txt will look like this:

The

dodgers

won

the

baseball

game

 

Any help is appreciated, thanks.

Link to comment
Share on other sites

You won't want to remove things as it may do things to the file, why not just only accept it if it contains the alphabetic chars?

 

http://uk2.php.net/manual/en/function.ctype-alpha.php

 

It's a text file. The only thing special about a text file is whether there are end of lines in there or not.  The worst that can happen is if you explicitly remove them, you won't have stuff on their own lines anymore.  The code I provided doesn't touch what may or may not already be there.  In fact if anything, maybe it should, since he wants the end product to be a list, and any new lines originally there would create blank lines.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.