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 :
<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";
}
}