Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ---<

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    well, instead of busting your balls, ( like everyone else seems to be doing here ;-)

    try this:

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

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ---<

  • #6
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yay, it works! thx

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    haha, i was just bugging,
    glad it worked out for you.

    cheers,
    -Ken


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •