Looking for PHP script to compare a list of strings to another list of strings

Discussion in 'Programming' started by archard, Sep 12, 2007.

  1. #1
    It doesn't necessarily have to be PHP but, basically I'm looking to create a script that has a pre-set list of strings and compares that list to other specified lists of strings and determines which ones match. Any ideas?
     
    archard, Sep 12, 2007 IP
  2. archard

    archard Peon

    Messages:
    221
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You know what let me completely rephrase this question. I need a script that will take a textarea, and map each line of the text area to an array. So for example if we have a textarea that looks like this:

    red
    blue
    green
    black
    yellow

    it will make "red" the first value in the array, "blue" the second value and so on...
     
    archard, Sep 12, 2007 IP
  3. DKameleon

    DKameleon Member

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #3
    I'm not sure that your explanation is clear enough, but according to your explanation it's enough to explode textarea variable:

    
    $arr = explode("\n", @$_POST["lines"]);
    // $arr will contain textarea values splitted in array elements line by line
    
    PHP:
     
    DKameleon, Sep 12, 2007 IP
  4. archard

    archard Peon

    Messages:
    221
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Perfect! Thank you! <3<3<3
     
    archard, Sep 12, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Maybe you should trim() the values as well, to remove possible carriage return characters.

    
    $arr = explode("\n", @$_POST["lines"]);
    $arr = array_filter(array_map('trim', $arr));
    
    PHP:
     
    nico_swd, Sep 12, 2007 IP