Filter data of a input from other input

Discussion in 'PHP' started by firstminister, Aug 19, 2012.

  1. #1
    Hi everyone..

    sweet ppl, i have a long time, looking for a script which make this:

    i need to filter, data of one input from the other one input! for example:

    I write phone numbers (per line) on the first textarea, and on the other, i put phone numbers that i want to remove from the first textarea, and print results of cleaned numbers on the same page.. someone can help me please! sorry for english errors, im hispanic
     
    firstminister, Aug 19, 2012 IP
  2. wwwprog

    wwwprog Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Let see source?
     
    wwwprog, Aug 19, 2012 IP
  3. firstminister

    firstminister Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I dont have any source bro! im looking for a source..

    Look, i want remove some numbers from a list of phone numbersm with a php script.. how can i do?
     
    firstminister, Aug 19, 2012 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    Pretty straightforward, just do something like this:

    <?php  
    function clean($emails, $filter) {
      foreach ($emails as $id => $email) {
        if (in_array($email, $filter)) {
          unset($emails[$id]);
        }
      }
      
      return $emails;  
    }
    
    
    var_dump(clean(array('a@example.com', 'b@example.com', 'c@example.com', 'd@example.com', 'e@example.com'), array('a@example.com', 'd@example.com')));
    PHP:
    Result:
    array(3) {  [1]=>
      string(13) "b@example.com"
      [2]=>
      string(13) "c@example.com"
      [4]=>
      string(13) "e@example.com"
    }
    
    Code (markup):
     
    Alex Roxon, Aug 20, 2012 IP
  5. firstminister

    firstminister Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok look what I'm looking for..

    i have a large phone numbers list, so i want remove, some unwanted numbers from there.. So I want make a form with two textarea inputs, where in the first I paste the phone numbers list, and in the seond, I place the numbers which I want to remove from list.. please help me with entire code
     
    firstminister, Aug 20, 2012 IP
  6. sh4rd

    sh4rd Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    People are unlikely to do everything for nothing. All you have to do is call the function clean (the one used in the previous example) with 2 arrays, 1 holding the phone numbers and the other with the numbers to be removed. The data from the text areas can be referenced through $_POST, then should be split (by a space/ comma) to for the arrays. It is only basic PHP (look on w3schools), and everything I have said has examples on the internet.
     
    sh4rd, Aug 20, 2012 IP
  7. wwwprog

    wwwprog Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    ok.
    just use it

    
    <style>
        .want{
            width: 200px;
            height: 500px;
        }
        .unwant{
            width: 200px;
            height: 500px;
        }
    </style>
    <form name="Form" method="post">
        <textarea name="1" class="want" placeholder="81881858859,81881858869,81881858879,81881858889,81881858899"></textarea>
        <textarea name="2" class="unwant" placeholder="81881858859"></textarea>
        <input type="submit" value="submit" />
    </form>
    <?php
    function clean($emails, $filter) {
      foreach ($emails as $id => $email) {
        if (in_array($email, $filter)) {
          unset($emails[$id]);
        }
      }
      
      return $emails;  
    }
    
    foreach(clean(explode(',',$_POST['1']), explode(',',$_POST['2'])) as $str){echo $str.'<br>';}
    
    PHP:
     
    wwwprog, Aug 21, 2012 IP