...

View Full Version : I'm a newbie...be gentle



flashguy97
09-01-2006, 05:34 PM
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 :)

Spookster
09-01-2006, 07:11 PM
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. (http://www.codingforums.com/postguide.htm)

rlemon
09-01-2006, 07:22 PM
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. (http://www.codingforums.com/postguide.htm)

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.

angst
09-01-2006, 07:40 PM
well, instead of busting your balls, ( like everyone else seems to be doing here ;-)

try this:

$MyString = preg_replace('/[^0-9a-z]/i','',$strValue);

rlemon
09-01-2006, 08:55 PM
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.:thumbsup:

flashguy97
09-01-2006, 08:56 PM
yay, it works! :D thx :)

angst
09-01-2006, 08:58 PM
haha, i was just bugging,
glad it worked out for you.

cheers,
-Ken



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum