Ashraf Eldawody Ashraf Eldawody -4 years ago 53
PHP Question

how to filter array value that contains numbers only

I have a file as array
'line number' => 'it's content';
now i need a way to remove lines that contains only numbers (without letters or special caracters)
i did it by the length of the line but this method is not appropriate because it might delete some of the contents

/*count file lines*/
$linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);

for($i=0; $i<=($linecount*2)-4;$i++) {
$length = strlen((string)$text[0][$i]);
if ($length >5)
{
echo ($text[0][$i] .'</br>');
}

}


is_numric didn't work i think because there is a space before the numbers

Answer Source

I modified the second line. Didn't understand why $length>5,it should $length>0

strlen(trim((string)$text[0][$i]));

for($i=0; $i<=($linecount*2)-4;$i++) {
$length = strlen(trim((string)$text[0][$i]));
if ($length >0) 
   {
       echo ($text[0][$i] .'</br>');
   }

}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download