how to get only the specific content from a file using PHP. -


how specific content file using php.

i have file content:

reference 1.pdb mobile 4r_1.pdb ignore fit mobile 4r_10.pdb ignore fit mobile 4r_22220.pdb ignore fit 

now, want take names i.e. (output)

4r_1 4r_10 4r_22220  

in array , print it.

the program have written in php doesn't work properly, can have look

$data = file_get_contents('file.txt'); // read file $convert = explode("\n", $data); // take in array $output4 = preg_grep("/mobile/i",$convert); //take line starts mobile , put in array if ($output4 !="/mobile/i") {  print $output4; print "\n"; } 

please help! extract names

try this:

$convert = explode("\n", $data); // take in array $filenames = array();   foreach ($convert $item) {     if(strstr($item,'mobile')) {         array_push($filenames,preg_replace('/mobile[\s]?([a-za-z0-9_]*).pdb/','${1}',$item));     } } 

now file names (assuming file names) in array $filenames


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -