Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-01-2006, 05:34 PM   PM User | #1
flashguy97
New to the CF scene

 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
flashguy97 is an unknown quantity at this point
I'm a newbie...be gentle

Hi,

I have a pretty large text file in which I'm trying to exclude any characters that arent numbers, letters or periods. Basically I want anything that's an odd character to be deleted or shown to me so I can delete it(?'s, /'s, etc.). I found the script below that might be a beginning. I'm pretty new to PHP (this is my second time around at using it) so please go easy on me.

<?php
$search_term = '?'
$array = file('c:/php/list.php'); //list.php is my text file
foreach ($array as $key => $value)
{
if (strpos($value, $search_term) !== False)
{
$line = $key + 1;
echo $search_term . ' was found on line #' . $line . '<br>';
}
}
?>

thx
flashguy97 is offline   Reply With Quote
Old 09-01-2006, 07:11 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,224
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Judging by your thread title it seems pretty obvious you didn't read our posting guidelines as we require everyone to do before posting in the forums. I'd recommend reading them now. See posting guidelines.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 09-01-2006, 07:22 PM   PM User | #3
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
Quote:
Originally Posted by Spookster
Judging by your thread title it seems pretty obvious you didn't read our posting guidelines as we require everyone to do before posting in the forums. I'd recommend reading them now. See posting guidelines.
well your attempt seems like it would do little to nothing as per what your trying to acheive. and... LOL that title is called out exactly. thats funny.

what you wanna do (or what i would do) is run a preg_match() on the valid characters and extract them all into an array. probably much easier than parsing.
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Old 09-01-2006, 07:40 PM   PM User | #4
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
well, instead of busting your balls, ( like everyone else seems to be doing here ;-)

try this:

$MyString = preg_replace('/[^0-9a-z]/i','',$strValue);
angst is offline   Reply With Quote
Old 09-01-2006, 08:55 PM   PM User | #5
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
Quote:
Originally Posted by angst
well, instead of busting your balls, ( like everyone else seems to be doing here ;-)

try this:

$MyString = preg_replace('/[^0-9a-z]/i','',$strValue);
or preg_replace, i just thought you might want all 'valid' values to be split out.

and i wasn't busting his balls. i was just saying. its' funny.
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Old 09-01-2006, 08:56 PM   PM User | #6
flashguy97
New to the CF scene

 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
flashguy97 is an unknown quantity at this point
yay, it works! thx
flashguy97 is offline   Reply With Quote
Old 09-01-2006, 08:58 PM   PM User | #7
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
haha, i was just bugging,
glad it worked out for you.

cheers,
-Ken
angst is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:22 AM.


Advertisement
Log in to turn off these ads.