I am calling a Shell Script, namely "scanTmp.sh" from within a PHP script using exec().
The Shell Script, in fact, has only one task to perform:
Code: Select all
contents=`ls -ltr /tmp | tail -n +2`The problem that I am now facing is: How to extract only the name part of the directory / file from the output such as:
Code: Select all
-rw-r--r-- 1 root root 0 Aug 30 16:50 2_b
-rw-r--r-- 1 root root 0 Aug 30 16:50 2_a
-rw-r--r-- 1 root root 0 Aug 30 16:50 1_d
-rw-r--r-- 1 root root 0 Aug 30 16:50 1_c
-rw-r--r-- 1 root root 0 Aug 30 16:50 1_b
-rw-r--r-- 1 root root 0 Aug 30 16:50 1_a
-rw-r--r-- 1 root root 133 Aug 31 19:52 August.txt
-rw-r--r-- 1 root root 1963 Aug 31 20:30 2010 ProgrammeCode: Select all
-rw-r--r-- 1 root root 1963 Aug 31 20:30 2010 ProgrammeWell, the purpose of extracting only file names is to enable the functionality of displaying the contents of that file after passing the file name as the parameter to another PHP script. We can create hyper links while listing the directory contents.
Please note that the solution I want is in PHP and not in Shell Script as the functionality is to be provided in the PHP Script while displaying the contents of the array that holds the output of the result returned by the function exec().
Any ideas?