如何从文本文件中为变量赋值? [关闭]

I am using a script to back up files from ftp. code is below.

include "recurseZip.php";
//Source file or directory to be compressed.
$src='source/images/black.png';
//Destination folder where we create Zip file.
$dst='backup';
$z=new recurseZip();
echo $z->compress($src,$dst);

Now I want to get values to $src from source/files.txt which contains a list of file names.

My .txt file:

index.php.bk-2013-12-02
index.php.bk-2013-12-07
index.php.bk-2013-12-10
index.php.bk-2013-12-20
index.php.bk-2013-12-26
function.php.bk-2013-12-20
function.php.bk-2013-12-23
contact.php.bk-2013-12-23
contact.php.bk-2013-12-30

my source/files.txt contains 10 file names those need to be assigned as values to the variable $src I am using this script http://ramui.com/articles/php-zip-files-and-directory.html

how can I do that.?

any help will be very much appreciated.

Thanks.

Okay, you want to get the file name from each line of the .txt file.

<?php
    $myFile = "files.txt";
    $lines = file($myFile);
    foreach($lines as $line){
    $file = basename($line);
    echo $file; 
    }
?>

Answer to your old question variant

You can use the basename() function. The manual says, "given a string containing the path to a file or directory, this function will return the trailing name component".

Now, you said "I want to get file name to $src from source/files.txt", so assuming from this, you are looking to get the file name i.e. black.png. This could be achieved using the basename() function as mentioned before.

<?php
$src='source/images/black.png';
$file = basename($src);
echo $file;
?>

Output

black.png

http://ideone.com/p2b4sr