我试图读取该文件名组成的文件,并写入数据库查询中使用的foreach - MV class.module.example.php class.module.examplejason.php为每名进入一份文件。的输出额外的点,而在PHP
这是我的代码:
$lines = file('/home/Staging/txts/textFile.txt');
$developer = "jason";
foreach ($lines as $line_num => $line)
{
$fileNameArray = array_reverse(explode("/",$line));
$fileNameArray2 = array_reverse(explode(".",$fileNameArray[0]));
$fileNameArray2[1] = $fileNameArray2[1].$developer;
$fileNameArray3 = array_reverse($fileNameArray2);
$j=0;
for($i=1;$i<count($fileNameArray2);$i++)
{
$dot=".";
if($j==$i)
{
$dot="";
}
$devFileName = $devFileName.$fileNameArray3[$i].$dot;
$j++;
}
$fileNameArray4 = $fileNameArray;
$fileNameArray4[0] = $devFileName;
$fileNameArray4 = implode("/",array_reverse($fileNameArray4));
echo "mv ".$fileNameArray[0]." ".$fileNameArray4."\r\n";
}
问题:
我在for循环结束时得到的输出是:
class.module.examplejason.php .
为什么我得到最后.
?我究竟做错了什么?如果我的文件中有2名,像/home/Staging/class.module.example.php和/home/Staging/class.module.anotherExample.php,输出为:
mv class.module.example.php /home/Staging/class.module.examplejason.php . mv class.module.anotherExample.php /home/Staging/class.module.anotherExamplejason.php .
谢谢。它起到了魅力! – mercy