Search code examples
phpstringnumberstextareapreg-match

numbers and next line only in the textarea field


I m trying to use following pattern

65465465465654
6546465465465465
5646545646464
6545646456
6454646456

in text area please anyone help me to check preg_match pattern for the above input type

I want to take mobile numbers separated by the next line character.


Solution

  • Try this:

    $numbers = "65465465465654
    6546465465465465
    5646545646464
    6545646456
    6454646456";
    
    preg_match_all("/([0-9]*)\n/", $numbers, $resultArray);
    
    foreach ($resultArray as $result) {
        preg_replace("/\n/", "", $result);
    }
    

    Output:

    array(4) {
      [0]=>
      string(14) "65465465465654"
      [1]=>
      string(16) "6546465465465465"
      [2]=>
      string(13) "5646545646464"
      [3]=>
      string(10) "6545646456"
    }