Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

extract only numbers from textarea using php

i have a textarea each line in textarea contains numbers or names , i want to extract only number from textarea .

this my code


<?php 

    $allUsers = $_POST['allusers'];
    foreach(explode("\n", $allUsers) as $line) {
        
        if (is_numeric($line)) {
            echo $line."\n";
        }

    }
?>

and example of textarea data :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<textarea>
156444
978455
amoka
123
auman
</textarea>

>Solution :

Remove whitespace around the line before checking if it’s numeric.

    foreach(explode("\n", $allUsers) as $line) {
        $line = trim($line);
        if (is_numeric($line)) {
            echo $line."\n";
        }
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading