My so far not so bad version to implement this is:
function bashFileConvert($file)
{
return preg_replace('/([^\/\s]+\s+[^\/]+)(\/|$)/','"${1}"${2}',$file);
}
which mostly processes the problem when there is a space in file name,like
$flie = '/usr/local/my test file.txt'
while will not be recognizable for bash,
so need to convert to
$file = '/usr/local/"my test file.txt"'
before callintg something like :
exec('ls ' . $file);
But there is still many other corner cases,like quote and '&' problem,
so,is there a ready version to do this job?
==================================
Now I tried escapeshellarg(),but a little strange here:
$file = '/usr/local/apache2/resumes_txt/5/San Francisco/qtzhang/Device "Engineer"/Job Resume Qintao Zhang.pdf.txt';
echo escapeshellarg($file);
D:\\test>php test.php
"/usr/local/apache2/resumes_txt/5/San Francisco/qtzhang/Device Engineer /Job Resume Qintao Zhang.pdf.txt"
seems with this function,quote is replaced with a space?