Little PHP problem. Help please.

Discussion in 'PHP' started by deviant, Dec 26, 2008.

  1. #1
    I have a numbers.txt file

    like (inside of the numbers.txt) file:

    NEED2921
    SUDA9281
    MUHEA921
    LEHJA222
    JJJKEL22
    SUDA9281

    I need a function that check the each line of numbers.txt file and show me same lines in the text.

    Example as the datas below function should write:
    SUDA9281

    Thank you.
     
    deviant, Dec 26, 2008 IP
  2. ferdousx

    ferdousx Peon

    Messages:
    168
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ferdousx, Dec 26, 2008 IP
  3. deviant

    deviant Peon

    Messages:
    58
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hello thank you for your answer.

    i'm not familiar with PHP. So this url will make no sense in my mind. :(
     
    deviant, Dec 26, 2008 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    Using file() is better for line reading.

    
    $file = file('numbers.txt');
    print_r($file);
    
    PHP:
     
    Kaizoku, Dec 26, 2008 IP
  5. deviant

    deviant Peon

    Messages:
    58
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    But how to check if there are same values exist on the lines?
     
    deviant, Dec 26, 2008 IP
  6. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #6
    So you want to display duplicates? That is easy to implement.

    
    $lines = file('numbers.txt');
    $count = count($lines);
    for ($i = 0; $i < $count; $i++) {
        $temp = $lines[$i];
        unset($lines[$i]);
        if (in_array($temp, $lines)) {
            echo $temp, '<br>';
        }
    }
    
    PHP:
    Looks pretty straightforward, if you need explanation I will gladly do it.
     
    Kaizoku, Dec 27, 2008 IP
  7. deviant

    deviant Peon

    Messages:
    58
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You are so kind. as i am not familiar with PHP I don't need any explanations but to add the archive better to add explanations for further questions regarding to this. thank you.
     
    deviant, Dec 27, 2008 IP